我的代码在下面,演示站点在这里:http://glimmer.rstudio.com/kdavenport/test1/
第一个输入(下拉)加载在global.R中定义的数据
第二个输入(下拉)通过df的"Service“列过滤此数据。
第三个输入(复选框)通过df的“圆形”列进一步过滤数据。
问题是,在第一步,所有可用的数据框都会显示出来,而不是步骤2中的“服务”过滤后可用的复选框。
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()))
})发布于 2013-09-09 21:00:37
反应性雏菊链接一直在工作,问题是将“圆形”列作为一个因素加载,而元素在子设置后作为dataframe属性持续存在。因此,我需要在设置数据之后使用droplevel()。我在下面添加了dat <- droplevels(dat):
# 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,]
dat <- droplevels(dat) # This is what fixed it
return(dat)
})发布于 2013-09-06 17:41:23
您可以通过分组checkboxInputs和使用conditionalPanel来适当地显示和隐藏来修复这个问题。
步骤:
伪码
# Only show this panel if a certain Service is selected
conditionalPanel(
condition = "input.service.option == 'filter2'",
checkboxInput(inputId = "opt.col1", label = "label1", value = FALSE),
checkboxInput(inputId = "opt.col3", label = "label3", value = FALSE),
)参见此示例 ( RStudio RStudio)和伴随的代码。 (Esp.在UI.R中使用多个条件面板的代码部分。)
https://stackoverflow.com/questions/18660225
复制相似问题