英文:
How to print multiple gt tables in a quarto chunk?
问题
我有一个`gt`表格的列表,我想要显示它们。我记得在RMarkdown中,我可以在带有`results="asis"`选项的代码块中使用`walk(tabs, print)`语句来实现这个功能。
我无法弄清楚在Quarto中如何做到这一点?有什么建议吗?
这是我尝试过的,但无法渲染。
---
title: "Untitled"
format: html
editor: source
---
```{r}
library(tidyverse)
library(gt)
df <- mtcars[1:5, 1:2]
tab <- gt(df)
```
```{r}
#| results: asis
rep(list(tab), 3) %>%
walk(print)
```
渲染时的错误如下:
Error running filter C:/Users/xxxxx/AppData/Local/Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:
.../Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:2555: attempt to concatenate a nil value (local 'v')
stack traceback:
.../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 = "asis"
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.
---
title: "Untitled"
format: html
editor: source
---
```{r}
library(tidyverse)
library(gt)
df <- mtcars[1:5, 1:2]
tab <- gt(df)
```
```{r}
#| results: asis
rep(list(tab), 3) %>%
walk(print)
```
The error in rendering is as follows:
Error running filter C:/Users/xxxxx/AppData/Local/Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:
.../Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:2555: attempt to concatenate a nil value (local 'v')
stack traceback:
.../Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:2562: in function <.../Programs/Quarto/share/filters/quarto-pre/quarto-pre.lua:2560>
答案1
得分: 1
Quarto 喜欢当你使用 gt
表格的 as_raw_html
函数进行呈现。
标题: "未命名"
格式: HTML
编辑器: 源代码
library(tidyverse)
library(gt)
df <- mtcars[1:5, 1:2]
tab <- gt(df)
#| 结果: 原样
rep(list(tab), 3) %>%
map(as_raw_html) |>
walk(print)
另外,我也遇到了相同的问题,即使我已经更新了 Quarto。
英文:
Quarto likes it when you feed it gt
tables as_raw_html
.
---
title: "Untitled"
format: html
editor: source
---
```{r}
library(tidyverse)
library(gt)
df <- mtcars[1:5, 1:2]
tab <- gt(df)
```
```{r}
#| results: asis
rep(list(tab), 3) %>%
map(as_raw_html) |>
walk(print)
```
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论