最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to share objects between R and webr chunks in a Quarto Live document - Stack Overflow

programmeradmin5浏览0评论

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!

发布评论

评论列表(0)

  1. 暂无评论