gt icon indicating copy to clipboard operation
gt copied to clipboard

`opt_interactive` does not work in loops inside Quarto

Open mcanouil opened this issue 1 year ago • 2 comments

Description

Using regular print or knitr::knit_child() tricks do not work to display gt tables when opt_interactive is used.

Reproducible example

---
title: "Quarto and Interactive Tables"
format: html
---

## Interactive (not working)

```{r}
#| results: asis
#| echo: false
#| panel: tabset
library(gt)
for (i in 1:2) {
  cat(sprintf("\n\n## Tab %s\n\n", i))
  print(opt_interactive(gt(head(gtcars))))
}
```

```{r}
#| results: asis
#| echo: false
#| panel: tabset
library(gt)
for (i in 3:4) {
  cat(sprintf("\n\n## Tab %s\n\n", i))
  cat(
    knitr::knit_child(
      quiet = TRUE,
      text = c(
        "```{r}",
        "#| results: asis",
        "#| echo: false",
        "print(opt_interactive(gt(head(gtcars))))",
        "```"
      )
    )
  )
}
```

## Static (working)

```{r}
#| results: asis
#| echo: false
#| panel: tabset
library(gt)
for (i in 1:2) {
  cat(sprintf("\n\n## Tab %s\n\n", i))
  print(gt(head(gtcars)))
}
```

```{r}
#| results: asis
#| echo: false
#| panel: tabset
library(gt)
for (i in 3:4) {
  cat(sprintf("\n\n## Tab %s\n\n", i))
  cat(
    knitr::knit_child(
      quiet = TRUE,
      text = c(
        "```{r}",
        "#| results: asis",
        "#| echo: false",
        "print(gt(head(gtcars)))",
        "```"
      )
    )
  )
}
```

Expected result

Tables should be displayed without and with opt_interactive().

Session info

  • Quarto latest development version.
R version 4.3.0 (2023-04-21)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.4

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.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: Europe/Paris
tzcode source: internal

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

other attached packages:
[1] devtools_2.4.5 usethis_2.2.0 

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.5    miniUI_0.1.1.1    compiler_4.3.0    renv_0.17.3-62    crayon_1.5.2      promises_1.2.0.1  Rcpp_1.0.10       stringr_1.5.0    
 [9] prompt_1.0.1      callr_3.7.3       later_1.3.1       fastmap_1.1.1     mime_0.12         R6_2.5.1          htmlwidgets_1.6.2 profvis_0.3.8    
[17] shiny_1.7.4       rlang_1.1.1       cachem_1.0.8      stringi_1.7.12    httpuv_1.6.11     fs_1.6.2          pkgload_1.3.2     memoise_2.0.1    
[25] cli_3.6.1         magrittr_2.0.3    ps_1.7.5          digest_0.6.31     processx_3.8.1    xtable_1.8-4      remotes_2.4.2     lifecycle_1.0.3  
[33] prettyunits_1.1.1 vctrs_0.6.2       glue_1.6.2        urlchecker_1.0.1  sessioninfo_1.2.2 pkgbuild_1.4.0    purrr_1.0.1       tools_4.3.0      
[41] ellipsis_0.3.2    htmltools_0.5.5

mcanouil avatar Jun 19 '23 16:06 mcanouil