Playing with webr

R in your browser
R
webr
datavisualization
Author

Michaël

Published

2024-01-29

Modified

2024-02-04

A photo of an Impala browsing a tree

Impala (Aepyceros melampus) female browsing Weeping Boer-Bean (Schotia brachypetala) leaves – CC-BY-SA by Bernard DUPONT

webr allows R to run in the browser from a quarto HTML document. Let’s play!

Add webr to your quarto environment, in the terminal:

quarto add coatless/quarto-webr

Then, in the YAML header, add:

engine: knitr
filters: 
  - "webr"
webr:
  packages:
    - "dplyr"
    - "ggplot2"
    - "duckdb"
    - "glue"
    - "ggokabeito"

Now enclose your chunks with {webr-r} instead of {r}.

{dplyr} is a large package, so installing/loading it can take a little time…

… should work. You can edit and re-run the code in all chunks!

We will explore the popular french baby names. It is in parquet format; we can use {arrow} or {duckdb} to open it. Here we try with {duckdb}…

However we can’t INSTALL (yet) a DuckDB extension that would have allowed us to directly query over HTTP without downloading the whole file:

So we download and use a local copy of the dataset:

How does it look like?

Get the 2022 most popular names and check their past evolution:

Some were already very popular a long time ago. Half are recent. Names are now much more diluted.