Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.
/ quarto-webr Public archive
forked from coatless/quarto-webr

Quarto extension to embed webr for html documents

Notifications You must be signed in to change notification settings

dataeducation/quarto-webr

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

webR Code Extension for Quarto HTML Documents

This extension enables the webR code cell in a Quarto HTML document.

quarto-webr Filter in Action

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:

Installation

To use this extension in a Quarto project, install it from within the project's working directory:

quarto install extension coatless/quarto-webr

Usage

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.

Known Hiccups

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:

Stuck at Loading webR...

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

Speed up webR

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.

Engine Registration

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.

Acknowledgements

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:

About

Quarto extension to embed webr for html documents

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 50.2%
  • HTML 48.0%
  • JavaScript 1.8%