• Stars
    star
    300
  • Rank 138,870 (Top 3 %)
  • Language
    TypeScript
  • License
    Other
  • Created almost 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This project aims to compile the statistical language R into WASM for use in a browser, via Emscripten.

Build, test and deploy webR codecov

WebR - R in the Browser

This project aims to compile the statistical language R (https://www.r-project.org/) into WebAssembly for use with a browser, via Emscripten (https://emscripten.org/). The repo includes patches to R's source code so that it can work in the browser environment provided by Emscripten and also includes a web-based REPL through the use of xterm.js.

Demo

A demo of the resulting R REPL can be found at https://webr.r-wasm.org/latest/. Please be patient as the Wasm runtime downloads and executes. R will display a banner message when it is ready to use.

Documentation

Documentation showing how to use webR in your own projects can be found at https://docs.r-wasm.org/webr/latest/

Downloading webR

The webR JavaScript package is available for download through npm and on CDN.

Complete release packages, including R WebAssembly binaries, are available to download for self hosting in the GitHub Releases section.

Building webR from source

R's source code and supporting libraries are written in both C/C++ and Fortran. Source files can be compiled with either a custom development version of LLVM flang (the default) or with gfortran and Dragonegg (using the --with-dragonegg configure option).

If you are compiling webR using the default toolchain, ensure that you first install the following required prerequisites:

  • Emscripten SDK (>=3.1.35)
  • cmake
  • gperf
  • liblzma
  • libpcre2
  • node (>=17.0.0)
  • quilt
  • wget

If you are compiling webR using Dragonegg, included in the source repository is a Dockerfile which can be used to setup the environment and Dragonegg toolchain.

Build instructions

Clone the repo into a new directory, cd into the directory, then run ./configure && make. You can configure make variables in a ~/.webr-config.mk file.

A dist directory is created which when finished contains the R Wasm files and an index.html file ready to serve the included R REPL app.

WebAssembly libraries

WebR relies on additional libraries compiled for Wasm for both Cairo graphics support and for building R packages that depend on certain system libraries. By default, only a minimal set of libraries are built for use with webR.

If you'd prefer to build all of the available system libraries for Wasm, cd into the libs directory and run make all to build the additional libraries, then finally cd .. and run make clean-webr && make to rebuild webR. R will automatically detect the additional Wasm libraries and integrate Cairo graphics support as part of the build.

Node and Emscripten versioning

WebR requires compiler and runtime support for WebAssembly.Exception, used internally for R error handling. This requires a version of Emscripten >= 3.1.35 and Node >= 17.0.0, which may be newer than the versions provided by your system package manager. An easy way to install and manage multiple versions of Node and Emscripten is by using nvm and emsdk.

The version of Node currently bundled by emsdk is 16.0.0. When building webR with this version of Node the process will fail with configure logs containing the error

WebAssembly.Tag is not a constructor

If this occurs, a newer version of Node should be installed and the following environment variable set before building webR, instructing Emscripten to use the newer version of Node:

export EM_NODE_JS=$(HOME)/.nvm/versions/node/v20.1.0/bin/node

If you are unsure of the correct path to Node the command which node should print the path in full.

Building on macOS Ventura 13.0+

At the time of writing the version of R used as the base for webR does not build cleanly using the macOS Ventura development SDK. If you are not using the included Dockerfile to build webR, the following extra setup must be done before starting the build process,

  • Install the GNU version of the patch program: e.g. brew install gpatch

More Repositories

1

shiny-standalone-webr-demo

Demonstration of using a JavaScript ServiceWorker to communicate with a running Shiny/httpuv session in webR.
JavaScript
59
star
2

pandoc-wasm

The universal document converter, compiled for WebAssembly and running in the browser.
Haskell
35
star
3

webr-ports

A repo for webR ports of R packages.
Shell
28
star
4

shiny-without-a-server-2023

Shiny Without a Server: webR & Shinylive - Jumping Rivers Shiny in Production Conference 2023
Lua
19
star
5

webr-webpack-example

An example of bundling webR as part of an application using webpack.
JavaScript
15
star
6

repo

A Cydia Repo for iOS tweaks hosted on github.
HTML
11
star
7

webr-node-example

An example of running webR under node.
JavaScript
9
star
8

webgl_gpe

A WebGL implementation of a 2D Gross-Pitaevskii Equation numerical solver. The solver runs in real time and is directly interactive. https://georgestagg.github.io/webgl_gpe
JavaScript
6
star
9

webr-nextjs-example

An example of running webR in a server component with Next.js.
CSS
6
star
10

reproducible-data-science-webr-shinylive-2024

Reproducible data science with webR and Shinylive 2024
Lua
6
star
11

webr-rmarkdown

A script to make code blocks in RMarkdown documents runnable
JavaScript
5
star
12

mnist-classifier-blas-wasm

MNIST Classifier - A WebAssembly BLAS Demo
JavaScript
5
star
13

webr-vue-example

An example of running webR in a Vue.js 3 application.
Vue
5
star
14

clifford-attractor

A webR experiment in drawing Clifford Attractors.
JavaScript
4
star
15

duckdb-flights-shinylive

An example Shinylive application demonstrating download of a .parquet file from a GitHub raw content URL and manipulating data with the {duckplyr} package.
R
4
star
16

webr-react-example

An example of running webR in a React application.
JavaScript
3
star
17

quartolivepkgdown

What the Package Does (One Line, Title Case)
Lua
2
star
18

thesis

LaTeX source of my PhD thesis: A Numerical Study of Vortices and Turbulence in Quantum Fluids.
TeX
2
star
19

3D-GP-MPIOMP

3D-GP-MPIOMP is a FORTRAN project designed to numerically solve the Gross-Pitaevskii equation (GPE) in three dimensions (3D) using MPI and OpenMP.
Fortran
2
star
20

3D-GP

3D Fork of 2D-GP (OLD: Do not use. Use 3D-GP-MPIMP instead)
Fortran
1
star
21

open-dyslexic-latex

Open Dyslexic font for LaTeX
TeX
1
star
22

graph-curvature-webapp

A mathematical tool for calculating various notions of discrete graph curvature.
JavaScript
1
star
23

actions

GitHub Actions associated with R WebAssembly tasks
1
star
24

quarto-ace-revealjs

Ace editor for Quarto presentations
JavaScript
1
star
25

webr-flang-docker

A Dockerfile used to create an image containing a patched `flang` for use when building webR.
Dockerfile
1
star
26

lustre-roll

Lustre client roll for rocks clusters
Shell
1
star
27

data-vis-in-the-browser-2023

JavaScript
1
star
28

pendulum

A double spherical pendulum solver/display in the browser.
JavaScript
1
star
29

interpolating-polynomials-wasm

A demo that finds interpolating polynomials for a set of points, demonstrating LAPACK routines running in a web browser using WebAssembly.
JavaScript
1
star