selectizeInput
在闪亮的输入( )中进行动态/条件过滤的正确方法是什么multiple = TRUE
?
在此示例中,我尝试显示受祖父过滤器限制的父过滤器(任何、全部、无),然后显示受父过滤器限制的子过滤器。
.getReactiveEnvironment()$currentContext 中的错误:如果没有活动的反应上下文,则不允许操作。(你试图做一些只能从反应式表达式或观察者内部完成的事情。)
---
title: "Example"
runtime: shiny
output:
flexdashboard::flex_dashboard:
vertical_layout: fill
---
```{r}
library(tidyverse)
library(flexdashboard)
library(shinyWidgets)
```
```{r global, include=FALSE}
filter_df <- data.frame(filter_GP = c("gpA", "gpA", "gpA", "gpB", "gpB", "gpB"),
filter_P = c("p1", "p1", "p2", "p3", "p4", "p4"),
filter_C = c("g", "h", "i", "j", "k", "l"))
data_df <- data.frame(y = seq(from=1, to=12),
filter_C = c("g", "g", "h", "h", "i", "i", "j", "j", "k", "k", "l", "l"))
data_df <-
data_df %>%
left_join(filter_df, by="filter_C")
```
Sidebar {.sidebar}
=====================================
```{r}
# grandparents
selectizeInput("GP", label = "Grandparents (multi-select):",
choices = unique(filter_df$filter_GP),
multiple = TRUE,
selected = "")
# parents
selectizeInput("P", label = "Parents (multi-select):",
choices = unique(filter_df[filter_df$filter_GP %in% input$GP, "filter_P"]),
multiple = TRUE,
selected = "")
# children
selectizeInput("C", 'Children (multi-select):',
choices = unique(filter_df[filter_df$filter_P %in% input$P, "filter_C"]),
multiple = TRUE,
selected = "")
```
Test
=====================================
更新
这是来自@heds1 的解决方案的 flexdashboard 版本:
---
title: "Example"
runtime: shiny
output:
flexdashboard::flex_dashboard:
vertical_layout: fill
---
```{r}
library(tidyverse)
library(flexdashboard)
library(shinyWidgets)
```
```{r global, include=FALSE}
filter_df <- data.frame(filter_GP = c("gpA", "gpA", "gpA", "gpB", "gpB", "gpB"),
filter_P = c("p1", "p1", "p2", "p3", "p4", "p4"),
filter_C = c("g", "h", "i", "j", "k", "l"))
data_df <- data.frame(y = seq(from=1, to=12),
filter_C = c("g", "g", "h", "h", "i", "i", "j", "j", "k", "k", "l", "l"))
data_df <-
data_df %>%
left_join(filter_df, by="filter_C")
```
Sidebar {.sidebar}
=====================================
```{r}
# grandparents
selectizeInput("GP", label = "Grandparents (multi-select):",
choices = unique(filter_df$filter_GP),
multiple = TRUE,
selected = "")
# parents
output$P <- renderUI({
df <- data_df[data_df$filter_GP %in% input$GP, ]
selectizeInput(
'P', 'Parents', choices = unique(df$filter_P), multiple = TRUE
)
})
uiOutput("P")
# children
output$C <- renderUI({
df <- data_df[data_df$filter_GP %in% input$GP, ]
df <- df[df$filter_P %in% input$P, ]
selectizeInput(
'C', 'Children', choices = unique(df$filter_C), multiple = TRUE
)
})
uiOutput("C")
```
Test
=====================================