Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ Then build your JupyterLite site:
jupyter lite build
```

## Configuration

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

```json
{
"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](https://jupyterlite.readthedocs.io/en/latest/howto/configure/config_files.html#jupyter-lite-json) for more information.

## Limitations

### Headers
Expand All @@ -51,7 +71,7 @@ While webR supports interrupting long running computations, interrupting cell ex

### Development install

Note: You will need NodeJS and Python 3.8+ 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.
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](https://yarnpkg.com/) that is installed with JupyterLab. You may use `yarn` or `npm` in lieu of `jlpm` below.

Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ dependencies:
- nodejs=20
# deps
- jupyterlab >=4.0,<5
- jupyterlite-core >=0.3.0rc1
- jupyterlite-core >=0.5.0
11 changes: 11 additions & 0 deletions jupyter-lite.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"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/"
}
}
}
}
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@r-wasm/jupyterlite-webr-kernel",
"version": "0.3.0",
"version": "0.5.0",
"description": "An R kernel for JupyterLite, powered by webR",
"keywords": [
"jupyter",
Expand Down Expand Up @@ -60,13 +60,14 @@
"watch:labextension": "jupyter labextension watch ."
},
"dependencies": {
"@jupyterlite/kernel": "^0.3.0-rc.1",
"@jupyterlite/server": "^0.3.0-rc.1",
"@jupyterlite/kernel": "^0.5.0",
"@jupyterlite/server": "^0.5.0",
"hash.js": "^1.1.7",
"webr": "^0.3.0"
"webr": "^0.4.2"
},
"devDependencies": {
"@jupyterlab/builder": "^4.1.5",
"@jupyterlab/builder": "^4.4.1",
"@jupyterlab/coreutils": "^6.4.0",
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
Expand Down Expand Up @@ -111,7 +112,7 @@
],
"hooks": {
"before-build-npm": [
"python -m pip install 'jupyterlab>=4.0.0,<5'",
"python -m pip install 'jupyterlab>=4.3.0,<5'",
"jlpm"
]
}
Expand Down
16 changes: 9 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[build-system]
requires = ["hatchling>=1.5.0", "jupyterlab>=4.1.0,<5", "hatch-nodejs-version>=0.3.2"]
requires = ["hatchling>=1.5.0", "jupyterlab>=4.3.0,<4.4", "hatch-nodejs-version>=0.3.2"]
build-backend = "hatchling.build"

[project]
name = "jupyterlite-webr"
readme = "README.md"
license = { file = "LICENSE" }
requires-python = ">=3.8"
requires-python = ">=3.9"
classifiers = [
"Framework :: Jupyter",
"Framework :: Jupyter :: JupyterLab",
Expand All @@ -16,19 +16,21 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dependencies = ["jupyterlite-core>=0.3.0rc1"]
dependencies = ["jupyterlite-core>=0.5,<0.6"]
dynamic = ["version", "description", "authors", "urls", "keywords"]

[project.optional-dependencies]
dev = [
"jupyterlab>=4.1.0,<5",
"jupyterlab>=4.3.0,<4.4",
"ruff==0.1.5",
"jupyterlite-pyodide-kernel>=0.3.0a0"
"jupyterlite-pyodide-kernel>=0.5.2",
"pkginfo>=1.10.0",
]

[tool.hatch.version]
Expand Down Expand Up @@ -77,7 +79,7 @@ version_cmd = "hatch version"

[tool.jupyter-releaser.hooks]
before-build-npm = [
"python -m pip install 'jupyterlab>=4.1.0,<5'",
"python -m pip install 'jupyterlab>=4.3.0,<4.4'",
"jlpm",
"jlpm build:prod"
]
Expand Down
29 changes: 27 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
import { JupyterLiteServer, JupyterLiteServerPlugin } from '@jupyterlite/server';
import { IKernel, IKernelSpecs } from '@jupyterlite/kernel';
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
import { WebRKernel } from './webr_kernel';
import logo32 from '!!file-loader?context=.!../style/logos/r-logo-32x32.png';
import logo64 from '!!file-loader?context=.!../style/logos/r-logo-64x64.png';
import type { WebROptions } from 'webr';

const PLUGIN_ID = '@r-wasm/webr-kernel-extension:kernel';

const server_kernel: JupyterLiteServerPlugin<void> = {
id: '@jupyterlite/webr-kernel-extension:kernel',
id: PLUGIN_ID,
autoStart: true,
requires: [IKernelSpecs],
activate: (app: JupyterLiteServer, kernelspecs: IKernelSpecs) => {
console.log(PageConfig.getOption('litePluginSettings'));
const config = JSON.parse(
PageConfig.getOption('litePluginSettings') || '{}'
)[PLUGIN_ID] || {};

const webROptions: WebROptions = {
REnv: {
R_HOME: '/usr/lib/R',
FONTCONFIG_PATH: '/etc/fonts',
R_ENABLE_JIT: '0',
},
};

if (config.baseUrl) {
webROptions.baseUrl = URLExt.parse(config.baseUrl).href;
}

if (config.repoUrl) {
webROptions.repoUrl = URLExt.parse(config.repoUrl).href;
}

kernelspecs.register({
spec: {
name: 'webR',
Expand All @@ -29,7 +54,7 @@ const server_kernel: JupyterLiteServerPlugin<void> = {
},
},
create: async (options: IKernel.IOptions): Promise<IKernel> => {
return new WebRKernel({ ...options });
return new WebRKernel({ ...options }, webROptions);
},
});
},
Expand Down
6 changes: 3 additions & 3 deletions src/webr_kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseKernel } from '@jupyterlite/kernel';
import { KernelMessage } from '@jupyterlab/services';
import { IKernel } from '@jupyterlite/kernel';

import { Console, WebR, Shelter} from 'webr';
import { Console, WebR, Shelter, WebROptions } from 'webr';
import { RList, RCharacter, RLogical } from 'webr';

const webRVersion = "0.3.0";
Expand All @@ -17,13 +17,13 @@ export class WebRKernel extends BaseKernel {
#bitmapCanvas: HTMLCanvasElement;
#lastPlot: string | null = null;

constructor(options: IKernel.IOptions) {
constructor(options: IKernel.IOptions, webROptions: WebROptions) {
super(options);
this.#webRConsole = new Console({
stdout: (line: string) => console.log(line),
stderr: (line: string) => console.error(line),
prompt: (prompt: string) => this.inputRequest({ prompt, password: false }),
});
}, webROptions);
this.webR = this.#webRConsole.webR;
this.init = this.setupEnvironment();
this.#bitmapCanvas = document.createElement('canvas');
Expand Down
Loading