R to Interactive R

Overview

We can use {quarto-panelize} to take a usual R code cell and convert it into an interactive cell powered by webR. In this guide, we’ll walk through the steps!

Code Cell

For example, let’s take the following R cell:

```{r}
1 + 1
```

Document Header modification

Next, in our document header, we need to specify both the panelize and webr filters under the filters key, e.g. 

---
title: "My title"
format: html
filters:
- panelize
- webr
---
Important

The order matters! Please make sure panelize comes before webr. Otherwise, the webr filter will not see the code cell.

You will also need to have the {quarto-webr} extension installed by typing in Terminal:

quarto add coatless/quarto-webr

Wraping the code cell

Next, we use a special class called .to-webr inside of a Div denoted by ::: around a usual R code cell, e.g. 

:::{.to-webr}
```{r}
1 + 1
```
:::

This allows us to ensure the computational order is maintained when translating from R to a {quarto-webr} code cell.

Result

As a result, we now have access to two tabs: Result and Interactive.

1 + 1
[1] 2

Autorun Code

You may wish to allow the interactive cells to be automatically run when the document opens by specifying in the document header:

---
title: "My title"
format: html
webr:
  cell-options:
    autorun: true
filters:
- panelize
- webr
---