Reputation: 277
I am trying to figure out how to use conditionalPanel
in Shiny to remove options from checkboxGroupInput
based on what is selected on the sliderInput
.
Below is my code: ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("XXXXX"),
sidebarLayout(
sidebarPanel(
checkboxGroupInput("product.input", label = "Labels",
choices=c("Product A"="P1",
"Product B"="P2",
"Product C"="P3",
"Product D"="P4",
"Product E"="P5",
"Product F"="P6"),
selected=c("P1", "P2","P3","P4","P5","P6")),
sliderInput("prod.input",
label = "Select Month",
sep="",
min =1 , max = 12, value = c(5,8),step=1),
conditionalPanel(condition="prod.input<5",
checkboxGroupInput("product.input", label = "Labels",
choices=c("Product A"="P1",
"Product B"="P2",
"Product E"="P5",
"Product F"="P6")))),
mainPanel((tabsetPanel(
tabPanel("Table1",h2("Table Header"),tableOutput("figure"))))))))
server.R
shinyServer(function(input, output) {
output$figure <- renderPlot({
})
}
)
When the slider input is less than 5, I want the two checkboxes "Product C" and "Product D" to disappear. When I use conditionalPanel, a new list appears instead of the same list being updated. How can I fix this?
Upvotes: 2
Views: 1952
Reputation: 1271
It seems to me like you could solve your issue by using updateCheckboxGroupInput
(see Shiny reference).
Upvotes: 2
Reputation: 1933
I'm not sure how to change the checkboxGroupInput using conditionalPanel, but it's pretty simple if you use renderUI:
ui.R
uiOutput('product.input')
server.R
output$product.input <- renderUI({
allchoices <- c("Product A" = "P1", "Product B" = "P2", "Product C" = "P3",
"Product D" = "P4", "Product E" = "P5", "Product F" = "P6")
if(input$prod.input[2] < 5) allchoices <- allchoices[-c(3:4)]
checkboxGroupInput("product.input", label = "Labels", choices = allchoices,
selected = allchoices)
})
ps.: I'm not sure, but I think that once you've stated an 'input-object' in the ui you can't really change it. If you were to use the conditionalPanel, you'd probably have to declare two of them, each of them with one of the possible declarations of 'product.input'.
Upvotes: 0