如何在 quarto 块中打印多个 gt 表格?

huangapple go评论95阅读模式
英文:

How to print multiple gt tables in a quarto chunk?

问题

  1. 我有一个`gt`表格的列表,我想要显示它们。我记得在RMarkdown中,我可以在带有`results="asis"`选项的代码块中使用`walk(tabs, print)`语句来实现这个功能。
  2. 我无法弄清楚在Quarto中如何做到这一点?有什么建议吗?
  3. 这是我尝试过的,但无法渲染。
  4. ---
  5. title: "Untitled"
  6. format: html
  7. editor: source
  8. ---
  9. ```{r}
  10. library(tidyverse)
  11. library(gt)
  12. df <- mtcars[1:5, 1:2]
  13. tab <- gt(df)
  14. ```
  15. ```{r}
  16. #| results: asis
  17. rep(list(tab), 3) %>%
  18. walk(print)
  19. ```
  20. 渲染时的错误如下:
  21. Error running filter C:/Users/xxxxx/AppData/Local/Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:
  22. .../Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:2555: attempt to concatenate a nil value (local 'v')
  23. stack traceback:
  24. .../Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:2562: in function <.../Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:2560>
英文:

I have a list of gt tables I'd like to display. I seem to recall in RMarkdown, I could use a walk(tabs, print) statement inside a chunk with with results = &quot;asis&quot; chunk option for this to work.

I can't figure out how to do this in Quarto? Any advice?

Here is what I tried, but it fails to render.

  1. ---
  2. title: &quot;Untitled&quot;
  3. format: html
  4. editor: source
  5. ---
  6. ```{r}
  7. library(tidyverse)
  8. library(gt)
  9. df &lt;- mtcars[1:5, 1:2]
  10. tab &lt;- gt(df)
  11. ```
  12. ```{r}
  13. #| results: asis
  14. rep(list(tab), 3) %&gt;%
  15. walk(print)
  16. ```

The error in rendering is as follows:

  1. Error running filter C:/Users/xxxxx/AppData/Local/Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:
  2. .../Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:2555: attempt to concatenate a nil value (local &#39;v&#39;)
  3. stack traceback:
  4. .../Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:2562: in function &lt;.../Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:2560&gt;

答案1

得分: 1

Quarto 喜欢当你使用 gt 表格的 as_raw_html 函数进行呈现。


标题: "未命名"
格式: HTML
编辑器: 源代码

  1. library(tidyverse)
  2. library(gt)
  3. df <- mtcars[1:5, 1:2]
  4. tab <- gt(df)
  1. #| 结果: 原样
  2. rep(list(tab), 3) %>%
  3. map(as_raw_html) |>
  4. walk(print)

另外,我也遇到了相同的问题,即使我已经更新了 Quarto。

英文:

Quarto likes it when you feed it gt tables as_raw_html.

  1. ---
  2. title: &quot;Untitled&quot;
  3. format: html
  4. editor: source
  5. ---
  6. ```{r}
  7. library(tidyverse)
  8. library(gt)
  9. df &lt;- mtcars[1:5, 1:2]
  10. tab &lt;- gt(df)
  11. ```
  12. ```{r}
  13. #| results: asis
  14. rep(list(tab), 3) %&gt;%
  15. map(as_raw_html) |&gt;
  16. walk(print)
  17. ```

ftr I was getting the same message you were even after I updated quarto.

答案2

得分: 0

我更新了quarto CLI软件,quarto包,rmarkdown和knitr,错误消失了。感谢所有提供帮助的人。

英文:

I updated the quarto CLI software, the quarto package, rmarkdown, and knitr, and the error went away. Appreciate everyone who chimed in.

huangapple
  • 本文由 发表于 2023年4月7日 03:06:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75952944.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定