Downloading WebR
Download from npm
The webR JavaScript loader has been published as an npm package so that it can be bundled as part of your npm managed JavaScript or TypeScript project.
Install the package by running,
npm i webr
Note that webr >=0.2.0
requires node >=17.0.0
.
Then import the WebR
class into your project and initialise a new instance of webR.
import { WebR } from 'webr';
const webR = new WebR();
await webR.init();
The default location from which webR will load the WebAssembly R binaries depends on the execution environment. When running in a browser, webR will download binaries from CDN at start-up. If webR is running under Node.js, it will load binaries from the local module installation directory.
If required, this behaviour can be overridden by self-hosting the contents of a webR release package (or building from source) and providing an alternative base URL for the WebROptions.baseUrl
configuration setting.
Download from CDN
To dynamically import webR in JavaScript, directly from CDN, first import the WebR
class using the CDN URL. Once the promise resolves initialise a new instance of webR.
import('https://webr.r-wasm.org/latest/webr.mjs').then(
async ({ WebR }) => {
const webR = new WebR();
await webR.init();
}; )
Replace latest
with a fixed version string, such as v0.1.1
, if you would like to maintain a fixed version of webR.
Download release package
Packages for released versions of webR can be downloaded from the releases section of the webR source repository. Release packages contain both the webR JavaScript loader and the R WebAssembly binaries.
The release package contents should be self-hosted on a web server that you control, and then the webR JavaScript loader can be imported in a similar way to above.
Build from source
It is possible to build webR from source by following the build instructions at the webR source repository. Building from source creates a customised webR release package.