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

Quarto嵌入Shiny用reactable报错:object 'output' not found

问题:Quarto嵌入Shiny+reactable时出现object 'output' not found错误

在Quarto Markdown文档中嵌入Shiny应用,使用reactable包实现交互式表格时无法正常运行,核心代码逻辑如下:

  • 定义输入控件:selectizeInput('OP', "Label:",choices = choices)
  • 在#|context: server块中编写表格渲染逻辑(遵循reactable的Shiny规范)
  • 通过reactableOutput("table")渲染表格

运行时触发错误:

Error in output$table <- renderReactable({ : object 'output' not found
Calls: .main ... withVisible -> eval_with_user_handlers -> eval -> eval

推测问题源于Shiny常规server函数写法与Quarto上下文机制的差异,以下是可复现代码:

---
format: html
server: shiny 
---

## Introduction

```{r}
#| context: data
#| include: false
library(dplyr)
library(reactable)

users <- c("user1","user2","user3")
#|context: server
library(reactable)
n <- 6
dat <- data.frame(id=1:n, 
                  date=seq.Date(as.Date("2020-12-26"), as.Date("2020-12-31"), "day"),
                  group=rep(LETTERS[1:2], n/2),
                  age=sample(18:30, n, replace=TRUE),
                  type=factor(paste("type", 1:n)),
                  x=rnorm(n))

output$tbl <- renderReactable({
  reactable(dat)
})
reactableOutput("tbl")
---

# 解决方案

Quarto中Shiny的server上下文代码需要包裹在`function(input, output, session)`函数内部,而非直接操作`output`对象。修改后的可复现代码如下:

```r
---
format: html
server: shiny 
---

## Introduction

```{r}
#| context: data
#| include: false
library(dplyr)
library(reactable)

users <- c("user1","user2","user3")
#|context: server
library(reactable)
n <- 6
dat <- data.frame(id=1:n, 
                  date=seq.Date(as.Date("2020-12-26"), as.Date("2020-12-31"), "day"),
                  group=rep(LETTERS[1:2], n/2),
                  age=sample(18:30, n, replace=TRUE),
                  type=factor(paste("type", 1:n)),
                  x=rnorm(n))

# 核心修改:将server逻辑包裹在函数内
function(input, output, session) {
  output$tbl <- renderReactable({
    reactable(dat)
  })
}
reactableOutput("tbl")
### 修改说明
- 在`#|context: server`块中,必须将所有涉及`input`/`output`的逻辑放在`function(input, output, session) { ... }`内部,这是Quarto整合Shiny的标准写法
- 原代码直接赋值`output$tbl`时,Quarto的server上下文尚未初始化`output`对象,因此抛出"object 'output' not found"错误

内容的提问来源于stack exchange,提问作者mxfilerelatedcache
相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 17:11:17