webR logo
Introduction to webR

R compiled to WebAssembly, running in the web browser

George Stagg

What is webR?

WebR is a version of R (currently based on R 4.3.0) that can run entirely in a web browser.

Why run software in a browser?

Lots of potential reasons!

  • Containerisation
  • Sandboxing
  • Interactivity
  • Reproducibility
  • Software portability
  • Universal binaries

Let me tell a story about my reasons for creating webR…

How can we allow R code to be evaluated on devices outside our control?

Existing solutions rely on an external R server

Solution: Evaluate R code locally inside a web browser!

WebR allows you to move computation of R code from server-side hardware to client devices

How it works - WebAssembly (2017)

  • Portable binary code format
  • Enables high-performance applications on web pages
  • Near-native execution speed
  • Supported by most modern browsers

How it works - Emscripten (2012)

  • C/C++ compiler for WebAssembly
  • Based on LLVM/Clang
  • Originally designed for ASM.js in web browsers
  • DOSBox, SQLite, Pyodide

Ways you can use webR

Applications taking advantage of webR’s technology

webR REPL app

🔗 webR REPL app

Live and interactive R code

Live and interactive R plotting

The webR quarto extension

  • Knowledge of web development and JavaScript is not required to use webR!

  • Quarto extensions can be used to integrate webR into materials - e.g 🔗 quarto-webr

  • Using webR with Quarto provides a quick and easy way to add interactive code blocks to
    • Teaching materials
    • Web pages
    • Presentations
  • Demo Document

R Packages

Binary R packages for Wasm are available, listed at https://repo.r-wasm.org

webR 0.2.0: 10324 packages available (about 51% of CRAN)

Not all of the packages have been tested! Here “available” means a package, along with all its prerequisites, can be built by the Wasm compiler.

Tidyverse & tidymodels

Geospatial data packages

DBI and RSQLite

Advanced - webR developer API

  • If you know JavaScript, you can use webR’s JavaScript API to integrate webR with existing web frameworks.

  • I won’t talk about this now, but documentation can be found online at
    🔗 https://docs.r-wasm.org/

  • If you’d like to know more, I’m speaking about webR’s JavaScript API on Wednesday.