我在应用程序中有两个pickerInputs。第一个pickerInput的代码段如下:
managers <- c('Ram', 'Vijay','Arun','Aswin')
dept <- c('A','B','C','D')
details <- data.frame("Managers" = managers, "Department" = dept)
pickerInput(
'manager', 'Manager',
choices = managers ,
c('Ram', 'Vijay','Arun','Aswin'),
multiple = TRUE
)
相应经理的部门列在数据框中详细信息
第二个pickerInput的代码段如下:
pickerInput('dept', 'Department', choices = dept, c('A','B','C','D'), multiple = TRUE)
因此,当从第一个pickerInput中选择经理时,相应的部门应显示在第二个pickerInput中。这应该动态完成。
在R中这可能吗?如果没有,还有其他替代方法可以实现此功能吗?
答案 0 :(得分:0)
您可以使用uiOutput
和renderUI
动态生成所需的输入对象。下面给出了一个可行的示例,希望对您有所帮助。
library(shiny)
library(shinyWidgets)
managers <- c('Ram', 'Vijay','Arun','Aswin')
dept <- c('A','B','C','D')
details <- data.frame("Managers" = managers, "Department" = dept, stringsAsFactors = F)
ui <- fluidPage(
pickerInput(
'manager', 'Manager',
choices = managers ,
c('Ram', 'Vijay','Arun','Aswin'),
multiple = TRUE
),
uiOutput('picker2')
)
server <- function(input, output, session) {
output$picker2 <- renderUI({
choices = details$Department[details$Managers %in% input$manager]
pickerInput('dept', 'Department', choices = choices, choices, multiple = TRUE)
})
}
shinyApp(ui, server)