【发布时间】:2021-10-15 09:56:04
【问题描述】:
我想根据 Shiny 输入值显示或隐藏 R flexdashboard 组件。为此,我正在尝试执行动态创建新的 3 级降价部分的代码。如果我运行以下代码,我将获得带有侧边栏和 3 个组件的预期文档 - 即,最终代码块创建“Section C”组件。
---
title: "Sample Flexdashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
```
## Sidebar {.sidebar}
```{r}
radioButtons(
"select",
"Show or hide component",
choices = c("Show" = "show", "Hide" = "hide"),
selected = "show"
)
```
## Column
### Section A
### Section B
```{r, results='asis'}
cat(paste0("\n",
"### ",
"Section C",
"\n"))
```
但是,当我使用以下内容作为我的最后一个块来根据“选择”输入值显示/隐藏部分 C 时,它会将 ### Section C 文本打印为部分 B 中的代码,而不是使用它创建一个新组件文本作为降价。
```{r, results='asis'}
renderPrint(
if (input$select == "show") {
cat(paste0("\n",
"### ",
"Section C",
"\n"))
}
)
```
也许有比 renderPrint 更好的函数?
【问题讨论】:
标签: r shiny flexdashboard