coatless / quarto-webr

Community developed Quarto Extension to Embed webR for HTML Documents, RevealJS, Websites, Blogs, and Books.
https://quarto-webr.thecoatlessprofessor.com/
395 stars 19 forks source link

[Bug]: using a package with `context: output` fails #105

Closed tomsing1 closed 10 months ago

tomsing1 commented 1 year ago

Bug description

I can successfully generate a ggplot plot when the webr-r quarto context is interactive, but changing it to output leads to an error because the ggplot2 package (specified in the YAML header) is no longer found.

Steps to reproduce

The following Quarto document uses the default interactive context and works:

---
title: "test"
format: html
engine: knitr
webr: 
  packages: ['ggplot2']
  show-startup-message: false
filters:
  - webr
---

This is a webr-enabled code cell in a Quarto HTML document.

```{webr-r}
#| context: interactive
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()

But changing the context to `output` results in `Error: there is no package called ‘ggplot2’`

````qmd
---
title: "test"
format: html
engine: knitr
webr: 
  packages: ['ggplot2']
  show-startup-message: false
filters:
  - webr
---

This is a webr-enabled code cell in a Quarto HTML document.

```{webr-r}
#| context: output
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()

### Your environment

- IDE: RStudio 2023.09.1+494
- OS: Mac OS X Sonoma 14.1 (23B74)
- R Session info

R version 4.3.1 (2023-06-16) Platform: aarch64-apple-darwin20 (64-bit) Running under: macOS Sonoma 14.1

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Los_Angeles tzcode source: internal

attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] gtable_0.3.4 jsonlite_1.8.7 dplyr_1.1.3 compiler_4.3.1
[5] tidyselect_1.2.0 parallel_4.3.1 tidyr_1.3.0 credentials_1.3.2 [9] scales_1.2.1 fastmap_1.1.1 ggplot2_3.4.3 R6_2.5.1
[13] generics_0.1.3 curl_5.0.2 knitr_1.44 htmlwidgets_1.6.2 [17] tibble_3.2.1 munsell_0.5.0 openssl_2.1.0 pillar_1.9.0
[21] rlang_1.1.1 utf8_1.2.3 xfun_0.40 sys_3.4.2
[25] lazyeval_0.2.2 viridisLite_0.4.2 plotly_4.10.2 cli_3.6.1
[29] magrittr_2.0.3 stringdist_0.9.10 digest_0.6.33 grid_4.3.1
[33] rstudioapi_0.15.0 askpass_1.2.0 lifecycle_1.0.3 vctrs_0.6.3
[37] glue_1.6.2 data.table_1.14.8 fcuk_0.1.21 fansi_1.0.4
[41] colorspace_2.1-0 purrr_1.0.2 httr_1.4.7 tools_4.3.1
[45] pkgconfig_2.0.3 htmltools_0.5.6



### Quarto check output

[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.55.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.3.450
      Path: /Applications/quarto/bin

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.11.4 (Conda)
      Path: /Users/sandmann/miniconda3/bin/python
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with conda install jupyter

[✓] Checking R installation...........OK
      Version: 4.3.1
      Path: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources
      LibPaths:
        - /Users/sandmann/Library/R/arm64/4.3/library
        - /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
      knitr: 1.44
      rmarkdown: 2.25

[✓] Checking Knitr engine render......OK
coatless commented 1 year ago

@tomsing1 thanks for the report! Unfortunately, this is an issue that crept up when we modified the startup routine. c.f. #88. We'll get a fix in for it within the next few days. I'll leave the ticket up to let you know when it's addressed.

coatless commented 10 months ago

@tomsing1 I reworked a bit on the non-interactive cells in #120. They should now respect the packages key completely.

demo-non-interactive-with-ggplot2-webr

Care to give it a go and let me know if something else is amiss?

quarto add coatless/quarto-webr@cell-state-manager
tomsing1 commented 10 months ago

@coatless Thank you so much for fixing the output context! Works for me, too. 👍

coatless commented 10 months ago

@tomsing1 awesome! Let me know if anything else comes up.

The next official version should be rolled out soon (tm) with a few more features that include this change. Feel free to use the main branch in the interim.

quarto add coatless/quarto-webr