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

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

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 = &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.

---
title: &quot;Untitled&quot;
format: html
editor: source
---

```{r}
library(tidyverse)
library(gt)
df &lt;- mtcars[1:5, 1:2] 
tab &lt;- gt(df)
```

```{r}
#| results: asis
rep(list(tab), 3) %&gt;%
  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 &#39;v&#39;)
stack traceback:
	.../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
编辑器: 源代码

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: &quot;Untitled&quot;
format: html
editor: source
---

```{r}
library(tidyverse)
library(gt)
df &lt;- mtcars[1:5, 1:2] 
tab &lt;- gt(df)

```

```{r}
#| results: asis
rep(list(tab), 3) %&gt;%
  map(as_raw_html) |&gt; 
  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.

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:

确定