observablehq / feedback

Customer submitted bugs and feature requests
42 stars 3 forks source link

Find a way to use WebR on Observable #557

Closed chrispahm closed 7 months ago

chrispahm commented 1 year ago

Is your feature request related to a problem? Please describe. I'd like to use WebR (the statistical language R compiled to WASM, https://github.com/georgestagg/webR) in an Observable notebook. The JS landscape is still lacking a robust framework for performing many basic statistical methods (e.g. logistic regression, see following discussion → https://talk.observablehq.com/t/observable-for-research-advanced-statistics/4538/1), and this would enable more researchers and data scientists who are familiar with R to work with Observable notebooks.

Describe the solution you'd like There are two options for enabling WebR on Observable that are outlined in the docs https://docs.r-wasm.org/webr/latest/serving.html

1) Allow SharedArrayBuffers: Serve certain HTTP headers so that the page is cross-origin isolated → This allows the SharedArrayBuffer based communication channel to be used. 2) Host webR worker scripts: Host the worker scripts somewhere in the same origin as the notebook loading webR → read here for more details host your own versions of the webR worker scripts somewhere in the same origin as the page loading webR

Describe alternatives you've considered 1) We've tried to get WebR to work in a notebook hosted on the Ambassador account, but couldn't get it to work due to not being able to run a ServiceWorker or use SharedArrayBuffers → https://observablehq.com/@ambassadors/hello-webr 2) Explored using pyodide instead of R: Since Python is also a general purpose language, the integration of statistical libraries feels very cumbersome, also I couldn't get regression models to run without running into illegible bugs 3) Tried running R using web-cpu: Service is down most of the time (maybe all of the time?), so this is not really an alternative

neocarto commented 1 year ago

Any news on this subject?

georgestagg commented 8 months ago

It should now be possible to use webR with Observable notebooks by using the PostMessage communication channel when initialising webR, as it does not require SharedArrayBuffer or the webR service worker.

I don't use Observable notebooks a lot, so this might not be idiomatic Observable code, but here is a short notebook I tried to put together with some examples of running R code in a few different ways supported by webR and plotting with the svglite R package and Observable itself: https://observablehq.com/d/6936259b898a25ce

chrispahm commented 8 months ago

Wow @georgestagg that's awesome! Thanks a lot for sharing and your amazing work on WebR! Using your code it should be possible to create a few convenience wrappers for some of the more popular stats methods.

neocarto commented 8 months ago

Awsome. Thank you 🍾

neocarto commented 8 months ago

Awsome. Thank you 🍾