coatless / quarto-webr

Community developed Quarto Extension to Embed webR for HTML Documents, RevealJS, Websites, Blogs, and Books.
https://quarto-webr.thecoatlessprofessor.com/
395 stars 19 forks source link

[Feature]: Reading data from a quarto webpage #221

Open wetlandscapes opened 3 months ago

wetlandscapes commented 3 months ago

Feature Description

First, thanks for all your hard work! This is an incredible package.

For reading and working with small amounts of data in webr, rather than referencing some external resource, could one potentially save the data of interest to a rendered quarto webpage with live cells and then use webr to access that data? In the context of quarto and knitr stuff, I think this would be data stored in a table attribute.

I'm not as familiar with this stuff as I should be, so I'm unclear if this would just mean adding some example code to qwebr-loading-data.qmd, as the functionality is already there (e.g., using {rvest}), or if this would require a lot of leg work in the context of webr, or even some javascript.

Just a thought!

coatless commented 3 months ago

@wetlandscapes a copy and fetch mechanism is needed to ingest the data into VFS. The extension could incorporate it by parsing values under resources; but, this might make things more complicated.

wetlandscapes commented 3 months ago

I appreciate that quick response. Given the complexity, maybe this is just something to keep in the back of our minds as time goes on.

As a work around (maybe that's not the right phrase), I did take a cursory stab at using {rvest} (which has a curl dependency, but the package still loaded), but it was very cursory and I wasn't able to immediately figure out how to point the live cell to the DOM. Maybe I'll find some time to dig into that later and if I do I'll report back. Happy to close the issue, or keep it open if you want the reminder.

coatless commented 3 months ago

@wetlandscapes I thought about it a bit ago here:

https://github.com/coatless/quarto-webr/issues/157#issue-2150374362

But time to implement that portion was MIA.

The official WASM quarto backend that just dropped has resources support, c.f.

https://r-wasm.github.io/quarto-live/other/resources.html

https://github.com/r-wasm/quarto-live

wetlandscapes commented 3 months ago

Fascinating! Thanks for pointing me to that project.

Just played around with the resources option of quarto-live extension and encountered two problems relative to what I was proposing (one of which I'll need to register with their repo), but the major issue is the same as you mentioned with using the VFS; using resources to load local data into the VFS is not persistent, while what I was proposing was to effectively ship data within the web page itself. This might be too much of an edge case to really matter, though, as most truly live websites should have access to data using the currently supported mechanisms. Just thought it would be neat to have this other option.

Thanks!

coatless commented 3 months ago

For page embedding, maybe look at the ojs_define() usage to embed the data set.

https://r-wasm.github.io/quarto-live/interactive/hybrid.html#build-time-ojs-data-source

Otherwise, I think you want:

https://github.com/r-wasm/quarto-live/issues/22