I’m using the Quarto Live extension (0.1.3-dev) to create interactive Quarto (1.6.40) documents that mix R code and OJS widgets. My document contains R, WebR and OJS chunks. In one of my R chunks, I create an object, but when I try to access this object in a WebR chunk, it fails.
Here’s a minimal example of my document (don't fet to run quarto add r-wasm/quarto-live
):
---
title: "Quarto Live"
format: live-html
webr:
packages:
- dplyr
- ggplot2
- palmerpenguins
---
{{< include ./_extensions/r-wasm/live/_knitr.qmd >}}
```{r}
library(palmerpenguins)
my_penguins <- penguins
```
```{webr}
#| edit: false
#| output: false
#| define:
#| - do_penguins_density
do_penguins_density <- function(measure) {
ggplot(my_penguins) +
aes(x = .data[[measure]], fill = species) +
geom_density(alpha = 0.8)
}
```
```{ojs}
//| echo: false
viewof measure = Inputs.select(
[ "flipper_length_mm", "bill_length_mm", "bill_depth_mm", "body_mass_g" ],
{ label: "Measure" }
);
do_penguins_density(measure);
```
It fails with the error message object 'my_penguins' not found
.
However it works well with ggplot(penguins)
in the webr chunk (it's almost the documentation example).
So my question is: What are the recommended ways to share objects (not only dataframes) between the two separate environments (R and WebR) in Quarto Live?
I try workarounds with define
and input
, and also with write/read_rds()
but it doesn't work.
Thanks!