This extension enables the webR code cell in a Quarto HTML document.
The goal of webR is to:
run R code in the browser without the need for an R server to execute the code
For more details on webR, please see:
To use this extension in a Quarto project, install it from within the project's working directory:
quarto install extension coatless/quarto-webr
For each document, place the the webr
filter in the document's header:
filters:
- webr
Then, place the code for webr
in a code block marked with {webr}
---
title: WebR in Quarto HTML Documents
format: html
filters:
- webr
---
This is a webr-enabled code cell in a Quarto HTML document.
```{webr}
fit = lm(mpg ~ am, data = mtcars)
summary(fit)
```
When quarto render or preview is called, the filter will add two files to the working directory webr-worker.js
and webr-serviceworker.js
. These files allow for the webR session to be started.
As this is an exciting new frontier, we're learning as we go. Or as my friend Lawrence says, "I like to build airplanes in the air-". Please take note of the following issues:
If webr-worker.js
or webr-serviceworker.js
are not found when the document loads either at the root /
or relative directory, then Loading webR...
will appear above the code cell instead of Run code
. Please make sure the files are at the same location as the quarto document. For example, the following structure will work:
.
├── demo-quarto-webr.qmd
├── webr-serviceworker.js
└── webr-worker.js
When serving webR documents, please try to ensure the COOP and COEP HTTP headers are set to speed up the process:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
For more details, please see: https://docs.r-wasm.org/webr/latest/serving.html Note, this requires a "hack" for GitHub Pages.
If using the knitr
engine instead of the jupyter
engine, there is a known warning
that will appear in the render processing output of:
Warning message:
In get_engine(options$engine) :
Unknown language engine 'webr' (must be registered via knit_engines$set()).
This warning does not prevent or impact the ability of the webr
filter to function.
Though, we would like to address it at some point since it is not aesthetically pleasing.
This repository builds ontop of the initial proof of concept for a standalone Quarto HTML document in:
https://github.com/coatless-r-n-d/webR-quarto-demos
The proof of concept leaned heavily on the webR developers public-facing examples:
For the extension, we greatly appreciated insights from:
- Extensions
- Quarto Documentation
- Pandoc Documentation