我正在try 用Quarto构建一个仪表板.一个初始目标是在Shiny服务器上调用仪表板时计算数据集中的 case 数量(稍后使用API检索).在"服务器"上下文中,我用输出$n- renderText(nrow(data)渲染n-county,然后try 用文本输出("n")在值框中检索它.然而,我只看到框中的代码,而不是计数.我做错了什么?(我try 过几种变体):
---
title: "Count N"
format: dashboard
server: shiny
---
```{r}
#| context: setup
data <- tibble::tibble(a = c(1, 2, 3)) # The data should always be retrieved from a server when the dashboard starts later, that's why I need the server context
```
## Row
```{r}
#| content: valuebox
#| title: "n1"
# renderText() with paste0
list(
value = textOutput("n1")
)
```
```{r}
#| content: valuebox
#| title: "n2"
# renderText() without paste0
list(
value = textOutput("n2")
)
```
```{r}
#| content: valuebox
#| title: "n3"
# it works with a blank (but boring) number
list(
value = 99
)
```
```{r}
#| context: server
n <- data |> nrow() |> as.character()
output$n1 <- renderText(n)
output$n2 <- renderText(paste0(n))
```