【发布时间】:2021-05-17 22:27:26
【问题描述】:
我正在尝试使用 Flexdashboard 构建一个闪亮的应用程序,我遇到了一个有趣的问题。本质上,我有一个带有两个 selectInput 下拉菜单的侧边栏。我希望第二个 selectInput 中的选择取决于第一个中的选择。到目前为止,我的方法是在第二个输入的两个动态生成的选项之间切换。这个Dynamic UI shiny 示例本质上正是我想要做的,但我认为我在从服务器/ui 格式转换为 Rmarkdown 格式时遇到了麻烦。
此时我有以下简化代码,它产生第一个 selectInput,但不是第二个 selectInput,它只是绘制一个 html 代码块。
---
title: "Shiny Test"
output: flexdashboard::flex_dashboard
runtime: shiny
---
Tab1
===============================================================================
Inputs {.sidebar}
-------------------------------------------------------------------------------
```{r}
selectInput('type', label = 'Input 1',
choices = c('choice1', 'choice2'))
reactive({
switch(input$type,
'choice1' = selectInput('select2',
label = 'Input 2',
choices = c('choice3', 'choice4')),
'choice2' = selectInput('select3', label = 'Input 3',
choices = c('choice5', 'choice6')))
})
```
Column {data-width=600}
-------------------------------------------------------------------------------
### Test Output
```{r}
```
我感觉我遗漏了一些非常简单的东西,但我似乎找不到在 Flexdashboard 的上下文中处理这个问题的任何东西。任何建议将不胜感激!
【问题讨论】:
-
一种方法是在服务器端处理它 (
input$type) 在renderUI中,然后在ui中处理uiOutput。
标签: r shiny flexdashboard shiny-reactivity