With webR, it’s possible to execute R code directly in a web browser
But, webR can do more than just executing lines of code!
Interact with the running R process and manipulate the environment
🤯
“This is magic!”
WebAssembly (Wasm) is a portable binary format designed so that code can run anywhere
Client-side — in web browsers
Server-side — in the cloud and on the edge
webR is a version of the R interpreter built for WebAssembly
Execute R code directly in a web browser, without a supporting R server
Alternatively, run an R process server-side using Node.js
Educational materials, package documentation
Interactive presentations
Notebook & literate programming
Portable R applications, reproducibility
Thanks James Balamuta — coatless/quarto-webr
🧙♂️
These examples are relatively simple, but demonstrate a new and useful workflow using webR,
These examples are relatively simple, but demonstrate a new and useful workflow using webR,
These examples are relatively simple, but demonstrate a new and useful workflow using webR,
These examples are relatively simple, but demonstrate a new and useful workflow using webR,
WebR enables a level of computation that might otherwise be awkward in JavaScript alone
const ret = await webR.evalR("penguins");
const data = await ret.toJs();
const penguins = data.values[0].values.map((_, idx) => {
return {
species: data.values[0].values[idx],
island: data.values[1].values[idx],
bill_length_mm: data.values[2].values[idx],
bill_depth_mm: data.values[3].values[idx],
sex: data.values[6].values[idx],
}
});
Plot.dot(penguins, {
x: "bill_length_mm",
y: "bill_depth_mm",
stroke: "species", symbol: "species",
channels: {island: "island", sex: "sex"},
tip: true
}).plot({ grid: true, symbol: { legend: true } })
Revealing the magic 🪄✨
An R object pointer is stored in a JavaScript Proxy object
A Proxy is a type of JavaScript object that allows you to intercept certain fundamental operations
Operations on R objects are converted into webR messages
R’s C API used to interact directly with objects in Wasm memory
Service Workers are another type of JavaScript Worker
Similar to Web Workers, but act as a Network Proxy for HTTP and WebSocket traffic
Service Workers can intercept network traffic and forward it to a running Wasm process
This is essentially how Shinylive for Python already works!
https://webr.r-wasm.org/v0.2.1/
npm install webr
https://docs.r-wasm.org/webr/v0.2.0/