Skip to main content

An R kernel for JupyterLite, powered by webR

Project description

WebR kernel for JupyterLite

This repository contains a JupyterLite kernel that uses webR to execute R code. When the kernel is started, the webR WebAssembly binaries are downloaded from CDN and loaded into the page.

Demonstration instance

A demo instance of JupyterLite including the webR kernel and a sample Jupyter notebook containing R code can be found at https://jupyter.r-wasm.org.

Install

This package is available via PyPI:

pip install jupyterlite-webr

Once installed, build your JupyterLite site:

jupyter lite build

The _output directory will contain the static JupyterLite site. You can serve it locally with the command,

jupyter lite serve

Configuration

The file jypyter-lite.json may be modified to set the webR base URL baseUrl and default package repository repoUrl. For example:

{
  "jupyter-lite-schema-version": 0,
  "jupyter-config-data": {
    "litePluginSettings": {
      "@r-wasm/webr-kernel-extension:kernel": {
        "baseUrl": "https://webr.r-wasm.org/latest/",
        "repoUrl": "https://repo.r-wasm.org/"
      }
    }
  }
}

See the Jupyterlite documentation on configuration files for more information.

Limitations

Headers

To use the webR kernel with JupyterLite, the page must be served with certain security-related HTTP headers so that it is cross-origin isolated. By setting these headers webR's SharedArrayBuffer based communication channel can be used:

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

Interruption

While webR supports interrupting long running computations, interrupting cell execution has not yet been implemented in JupyterLite. An infinite looping cell can only be recovered by restarting the kernel.

Contributing

Development installation

First, install a development version of the package from GitHub:

pip install git+https://github.com/r-wasm/jupyterlite-webr-kernel.git

or from a local clone:

git clone https://github.com/r-wasm/jupyterlite-webr-kernel
cd jupyterlite-webr-kernel
pip install .

Note: You will need NodeJS and Python 3.9+ to build the extension package. There is an environment.yml file for conda/mamba/micromamba users to create a conda environment with the required dependencies.

The jlpm command is JupyterLab's pinned version of yarn that is installed with JupyterLab. You may use yarn or npm in lieu of jlpm below.

# Clone the repo to your local environment
# Change directory to the jupyterlite-webr-kernel directory
# Install package in development mode
python -m pip install -e ".[dev]"

# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite

# Rebuild extension Typescript source after making changes
jlpm run build

# Rebuild JupyterLite after making changes
jupyter lite clean && jupyter lite build

To serve the extension with the JupyterLite server, you will need to set the required HTTP headers. The config.json file in this repository contains the required headers. You can start the JupyterLite server with the following command:

jupyter lite serve --config=config.json

Note that making changes to the extension will not automatically re-install the extension in the JupyterLite server. You will need to re-build and restart the server to see changes in the extension.

jupyter lite clean && jupyter lite build && jupyter lite serve --config=config.json

Development uninstall

pip uninstall jupyterlite-webr-kernel

In development mode, you will also need to remove the symlink created by jupyter labextension develop command. To find its location, you can run jupyter labextension list to figure out where the labextensions folder is located. Then you can remove the symlink named jupyterlite-webr-kernel within that folder.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyterlite_webr-0.5.1.tar.gz (160.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jupyterlite_webr-0.5.1-py3-none-any.whl (89.7 kB view details)

Uploaded Python 3

File details

Details for the file jupyterlite_webr-0.5.1.tar.gz.

File metadata

  • Download URL: jupyterlite_webr-0.5.1.tar.gz
  • Upload date:
  • Size: 160.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for jupyterlite_webr-0.5.1.tar.gz
Algorithm Hash digest
SHA256 6cd5fbbedbcca4d8de2ed45a0463f876283c083c0cac98ae81e00295246c1164
MD5 7f61269e3ceba7186c43fc67333f7349
BLAKE2b-256 247ac65d0dd99a1edcb311e5c3ab773ede2438cfce3ff5aaae86daaf56a785c2

See more details on using hashes here.

File details

Details for the file jupyterlite_webr-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for jupyterlite_webr-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9dc4a9c27a9b7d8ca2a8c93102cd07a0d027cb78753768c7cce611faa93ca030
MD5 36e929b45a3ba9b7973c975b38c43f9f
BLAKE2b-256 3dce5a6b494906441c81539b85fdaeac219bdc7e7d24dd4654a4fed210ca6a9e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page