You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Quarto中使用gt包循环生成标签页的异常问题

问题:Quarto动态生成标签页时{gt}包的异常交互

我尝试通过遍历变量(示例中用homeworld)结合results: asis代码块选项动态生成标签页,但与{gt}包交互时出现异常:在purrr::walk循环中必须使用gt::as_raw_html()才能正常渲染表格,而单独生成单个gt表格时无需该函数,否则会触发如下错误:

运行过滤器时出错
/Applications/quarto/share/filters/quarto-pre/quarto-pre.lua:
...lications/quarto/share/filters/quarto-pre/quarto-pre.lua:2410:
尝试拼接nil值(局部变量'v')调用栈跟踪:
...lications/quarto/share/filters/quarto-pre/quarto-pre.lua:2417: 在函数
<...lications/quarto/share/filters/quarto-pre/quarto-pre.lua:2415>

以下是Quarto 1.1.175版本的复现代码:

---
title: "Untitled"
format: html
execute:
  warning: false
---
library(dplyr)
library(glue)
library(gt)
library(purrr)

## 简化数据集
starwars <- starwars %>% 
  filter(!is.na(sex))
可行代码

::: {.panel-tabset}

#| results: asis

walk(
  unique(starwars$sex), \(hw) {
    cat(glue("## {hw} \n\n"))
    
    starwars %>% 
      filter(sex == hw) %>% 
      count(homeworld) %>% 
      head() %>% 
      gt() %>% 
      as_raw_html() %>% 
      print()
    
    cat("\n\n")
  }
)

:::

不可行代码(移除as_raw_html()后报错)

::: {.panel-tabset}

#| results: asis
#| eval: false

walk(
  unique(starwars$sex), \(hw) {
    cat(glue("## {hw} \n\n"))
    
    starwars %>% 
      filter(sex == hw) %>% 
      count(homeworld) %>% 
      head() %>% 
      gt() %>% 
      print()
    
    cat("\n\n")
  }
)

:::

单个表格可行代码

#| results: asis
starwars %>% 
  count(homeworld) %>% 
  head() %>% 
  gt()

内容的提问来源于stack exchange,提问作者boshek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 09:24:27