I've been playing around with R shiny, and have a question.
I want to create a multi-tab multi-dataset package. As the different datasets are not overly related, I want the user to be able to select which they want to look at and for that to change what filtering options are available for them to then use.
So I want something like this,
selectInput("variable", "Variable:",
list(""Cylinders" = "cyl",
"Transmission" = "am"),
if (selectInput == "Transmission") {
sliderInput("integer", "Integer:",
min=0, max=1, value=0) },
else{
sliderInput("decimal", "Decimal:",
min = 0, max = 1, value = 1) }
how do I do a conditional in Shiny? Treating it like a normal R conditional doesn't seem to work.
conditionalPanel
is what you want. http://rstudio.github.com/shiny/tutorial/#dynamic-ui
selectInput("variable", "Variable:",
list(""Cylinders" = "cyl",
"Transmission" = "am"),
conditionalPanel(condition = "input.variable == 'am'",
sliderInput("integer", "Integer:",
min=0, max=1, value=0)),
conditionalPanel(condition = "input.variable == 'cyl'",
sliderInput("decimal", "Decimal:",
min = 0, max = 1, value = 1))
(I haven't actually tried to run this code but you should be able to get the idea)
Note that conditionalPanel just hides the control, the child control still exists whether it is showing or not. In your server logic, you'll have to use if (input$variable == 'am')
to see what your mode you're in (which is probably the natural way anyway) rather than testing for the existence of input$integer
or input$decimal
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With