Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Observable Plot? #484

Open
ArthurAndrews opened this issue Jan 21, 2024 · 5 comments
Open

Add support for Observable Plot? #484

ArthurAndrews opened this issue Jan 21, 2024 · 5 comments

Comments

@ArthurAndrews
Copy link

I don't know if this is possible, but it would be really neat to have a tighter integration between R and Observable Plot as an htmlwidget.

It's currently possible to pass data to Observable in Quarto, and this is really powerful, but an htmlwidget would allow users to use Observable Plot from R code alone.

@timelyportfolio
Copy link
Collaborator

Agreed @juba started https://github.com/juba/obsplot but has appears to have shifted focus to maintaining the pyobsplot. Perhaps we should revive his efforts.

@ArthurAndrews
Copy link
Author

ArthurAndrews commented Jan 22, 2024

I just took a look at the obsplot package. Seems very ambitious! in terms of R function interfaces.

I can only speak for myself, but I would be happy with a very plain R list() input to Plot that's up-to-date with Observable and on CRAN.

The ojs chunks in Quarto are nice, but they limit its use to notebook chunks - not apps, html table cells, etc. And actually the ojs chunks don't yet render in RStudio, so the current workflow is not that nice.

htmlwidgets is great tool and Observable Plot seems like a worthy addition :)

@juba
Copy link

juba commented Jan 23, 2024

I can confirm that obsplot is not developed anymore and I don't think I will get back to it. That said I'm not sure I would make the same design choices if I had to start over now.

@timelyportfolio
Copy link
Collaborator

In a very raw and most basic form, here is a quick little attempt at an htmlwidget wrapper oplot. The design of Observable Plot does not translate well into htmlwidgets, since Plot uses functions rather than a json spec. I am going to try to think through how we might better support in R without needing an endless stream of htmlwidgets::JS or just an inelegant JavaScript eval.

@juba
Copy link

juba commented Jan 29, 2024

In pyobsplot I sort of make a custom serialization of Plot declaration in Python to json. Plot function calls are converted to objects with a property py-obsplot-type : "function". The parsing and serialization code is here:

https://github.com/juba/pyobsplot/blob/main/src/pyobsplot/parsing.py

It is then "deserialized" and run in JavaScript. Code is here:

https://github.com/juba/pyobsplot/blob/main/packages/pyobsplot-js/parsing.js

I also added a special handling of data attributes, to avoid duplication as they are often repeated in a Plot declaration. Data frames are serialized via Arrow IPC format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants