r-wasm / webr

The statistical language R compiled to WebAssembly via Emscripten, for use in web browsers and Node.
https://docs.r-wasm.org/webr/latest/
Other
805 stars 54 forks source link

Any good suggestions for use webr on electron? #394

Closed zpinocchio closed 2 months ago

zpinocchio commented 3 months ago

electron has a main process and a render process. when the config like this: nodeIntegration: true, contextIsolation: false, i don't want load from CDN, just want plot some in render process.

georgestagg commented 3 months ago

I have not tried webR in electron, but I think in theory this should work. When you start webR an options argument can be passed of type WebROptions. One of the settings here, baseUrl allows you to set where the webR binaries are downloaded from.

To use a relative version of webR, rather than loading from CDN, first download and extract a webR release package (from https://github.com/r-wasm/webr/releases) somewhere onto your system so that it is available as a relative URL in electron. Let's say the relative directory is something like ./libs/webr/.

Then, when you are loading webR set the baseUrl option to point to this directory:

const webR = new WebR({
  baseUrl: "./libs/webr/",
});
zpinocchio commented 3 months ago

Thank you for your patience, your answers have helped me a lot!