webR (wasm)

Is there a way tu use webR within Observable ?

Not yet. Please see this issue for more details:

Not Yet? Does this mean that it is planned?


No, it means that it’s currently not possible without changes to the platform or to webR. We’ll be looking into it though.

I understand. It’s both technical and a strategic choices. From my point of view, being able to call statistical functions from R in Observable then build dataviz with Plot or D3js would be really wow!!! To be continued…

1 Like

I created a website to run webR in JupyterLite, and got it to work iframed in an Observable notebook:

This via raw import worn’t work: https:// docs .r-wasm.org/webr/v0.1.0/serving.html#sw-cdn

This hack won’t work either: https:// docs .r-wasm.org/webr/latest/downloading.html#download-from-cdn

because we can’t properly set SW_URL correctly, even if we add the worker js as FileAttachments, first b/c it munges the names, and second b/c of origin issues (ref: WebR Busted / boB Rudis | Observable)

Observable wld have to do some clever wiring up of stuff to make WebR work in current form.

(I’m a new user in the forums so had to defang a couple URLs)

1 Like

@hrbrmstr Please see the issue that I linked in my first comment. It describes the challenges that are currently getting in the way of using webR on Observable.

Origin problems can be overcome by fetching the worker file and instantiating it from an object URL (see e.g. here).

As noted in my post. I 100% grok the difficulty. And, I actually don’t think it’s a priority (virtually anything WebR can do JavaScript + libs can do, now). Just trying to let folks know it’s a complex situation.

virtually anything WebR can do JavaScript + libs can do, now

I don’t think this is true, at least not in practice. R code forms the basis of analyses made in many disciplines (e.g., social sciences, genetics)—decades of tradition there. Using JS for data analysis is still relatively new, and I would be surprised to see that every analysis package the R community developed since the 90s has a JS equivalent.

Therefore, I either have to re-write a complex analysis code from scratch before I can visualize it on Observable (while always possible theoretically, often not feasible practically, for instance, in the case of statistical network analysis), or stick to R Shiny, effectively making a bridge between the analysis code (R) and visualization code (D3) while having to stay in R’s environment.

Besides, even if I could find a JS equivalent of 10-20 packages used in an average data preprocessing and analysis pipeline in R, many of my academic clients expect the analysis code they wrote to remain the same, while I add an additional analysis, visualization, or interface layer on top of it, often making my use of JS for the core analysis undesirable for the client. Some statistical analysis code written in R comes from (associate/assistant/full) professors, for instance, and re-writing them in JS, even if there would be a matching JS library for them, would essentially turn these analyses into black boxes for the research team, casting doubt on the code.

I would have very much welcomed webR integration in Observable so that the huge number of statistical analysis libraries from the R community can be brought into the pre-visualization code (at least in the future, as more of them become available for use in webR), and existing analyses in R can be reused.