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 @r-wasm/webr

Then import the WebR class into your project and initialise a new instance of webR.

import { WebR } from '@r-wasm/webr';

const webR = new WebR();
await webR.init();

By default, webR will download the WebAssembly R binaries from CDN at start-up. 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.WEBR_URL 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.0, 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.