webR 0.5.4

  wasm, webr

  George Stagg

We’re indubitably delighted to announce the release of webR 0.5.4. WebR brings R to the web browser using WebAssembly, powering Quarto Live, Shinylive, and other interactive websites with client-side R sessions.

This post highlights some key changes in recent webR releases. We’ve updated to R 4.5.1, upgraded the Emscripten version, implemented shareable URLs in the webR application, and added filesystem support for JupyterLite. For a complete list of changes, see the GitHub release notes.

R and Emscripten upgrades

Our WebAssembly compiled version of R is now up to date with R 4.5.1, ensuring that we have access to all the latest R core improvements and bug fixes. Under the hood, we’ve also upgraded Emscripten to version 4.0.8 and updated the version of LLVM we use to compile Fortran sources to 20.1.4.

Emscripten serves as the crucial layer between the web browser and R’s source code, playing a role similar to an operating system. Upgrading Emscripten and LLVM ensures we’re taking advantage of the latest WebAssembly features provided by both projects.

JupyterLite filesystem support

The webR JupyterLite kernel now targets the latest JupyterLite 0.6 series. An exciting improvement is the addition of a virtual filesystem driver designed specifically for use with JupyterLite. Files uploaded to JupyterLite’s filesystem are now accessible to webR, and conversely, files created by webR can now be downloaded through the JupyterLite web interface.

Screenshot of JupyterLite running the webR kernel. A data file is shown uploaded to the JupyterLite UI and loaded into the webR session.

To try out these new features, visit https://jupyter.r-wasm.org, which has been upgraded to include both the latest version of JupyterLite and our webR kernel.

Sharing URLs in the webR application

The webR application has been updated to support URL-based sharing. When you edit and save your files using the online editor, the application automatically updates the page URL to encode the current state of all open files.

Copy and share the URL with colleagues and they’ll be able to see exactly what you’re working on, providing an effortless way to share R code examples.

Screenshot of the webR application. A sharing URL is shown in a modal display.

Try it out for yourself! This link will open the webR application with a pre-loaded example R script.

Changes for web developers

Returning JavaScript objects to R

The eval_js() function has been enhanced and can now return a wider variety of R object types beyond scalar integers.

# Previously, only integers could be returned
webr::eval_js("1729")
#> [1] 1729

# Now, structured outputs can be returned 
df <- webr::eval_js("({foo: [1,2,3], bar: [4,5,6], baz: ['a', 'b', 'c']})")
class(df)
#> [1] "data.frame"
df
#>   foo bar baz
#> 1   1   4   a
#> 2   2   5   b
#> 3   3   6   c

By default JavaScript objects are converted to R data frames, matching the existing behaviour of Quarto Live when sharing data between OJS and R, but you can also use R object constructors for more control over the conversion process.

In addition, the RList constructor now recursively converts JavaScript objects into R lists, rather than just the outer object only. This is usually what we want when working with complex nested structures.

# The inner object `baz` is now converted into a nested R list
webr::eval_js("new RList({foo: 123, bar: ['a', 'z'], baz: {x: 2, y: [7, 1, 8]}})")
#> $foo
#> [1] 123
#> 
#> $bar
#> [1] "a" "z"
#> 
#> $baz
#> $baz$x
#> [1] 2
#> 
#> $baz$y
#> [1] 7 1 8

Filesystem API

Filesystem errors now provide more specific information. Instead of a simple generic "FS Error" message, you’ll also see "ErrnoError: n" where n is the actual error number as returned by the Emscripten Filesystem API, making debugging easier.

We’ve also exposed some additional Emscripten filesystem API functions on the WebR.FS JavaScript interface, so that they can be accessed from the webR main thread.

Acknowledgements

Thank you, as always, to the users and developers contributing to webR in the form of discussion in issues, bug reports, and pull requests.

@agmath, @aixnr, @ajostel, @allefeld, @baogorek, @christianp, @dipterix, @Dual-Ice, @durraniu, @dusadrian, @econstar, @EduardBel, @eitsupi, @gergness, @gregvolny, @H4x0rcr4x, @Hasnep, @holtzy, @JeremyPasco, @jeroen, @jgf5013, @jmbo1190, @Josselyn142, @jrosell, @kwgish, @lauralambert99, @madhur-tandon, @manojkumaryejjala, @manuelgirbal, @perhurt, @psychemedia, @Quantilogy, @richarddmorey, @schloerke, @sn248, @vsk-1167, @wch, @yhm-amber, and @zpinocchio.