我的代码如下,演示站点在这里: http: //glimmer.rstudio.com/kdavenport/test1/
第一个输入(下拉菜单)加载 global.R 中定义的数据框
第二个输入(下拉菜单)通过 df 的“服务”列过滤此数据框
第三个输入(复选框)通过 df 的“Round”列进一步过滤数据框
问题是显示了第一步中数据框可用的所有复选框,而不是在步骤 2 中按“服务”过滤后可用的复选框。下面我有 1.clientData > serviceFiltered_clientData > roundFiltered_clientData
shinyServer(function(input, output) {
# First UI input (Service column) filter clientData
output$serviceControls <- renderUI({
if (is.null(clientData()))
return("No client selected")
selectInput("service_select",
"Choose Service:",
choices = as.character(levels(clientData()$Service.Name)),
selected = input$service_select
)
})
# Second UI input (Rounds column) filter service-filtered clientData
output$roundControls <- renderUI({
if (is.null(serviceFiltered_clientData()))
return("No service selected")
checkboxGroupInput("round_select",
"Choose Round:",
choices = as.character(levels(serviceFiltered_clientData()$Round)))
})
# First data load (client data)
clientData <- reactive({
if (is.null(input$client_select))
return(NULL)
get(input$client_select)
})
# Second data load (filter by service column)
serviceFiltered_clientData <- reactive({
dat <- clientData()
if (is.null(dat))
return(NULL)
if (!is.null(input$service_select)) # !
dat <- dat[dat$Service.Name %in% input$service_select,]
return(dat)
})
# Third data load (filter by round column)
roundFiltered_clientData <- reactive({
dat <- serviceFiltered_clientData()
if (is.null(dat))
return(NULL)
if (!is.null(input$round_select)) # !
dat <- dat[dat$Round %in% input$round_select,]
return(dat)
})
# Audit count panel
output$auditsCount <- renderText({
if (is.null(roundFiltered_clientData()))
return("No client selected")
paste("Total Audits:",nrow(roundFiltered_clientData()))
})