In this shiny app I need to allow the user to tick one checkbox only. Is there anyway to achieve this?
ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("abc"),
sidebarLayout(
sidebarPanel(
checkboxGroupInput("choice", "What will you like to see?",
choices=c("red","green")),
conditionalPanel(
condition = "input.choice == 'red'",
sliderInput("slider1","slide",min=0,max=100,value=100,step=1,animate=TRUE)),
conditionalPanel(
condition="input.choice=='green'",
selectInput("choice","Select", c("a","b","c")),
sliderInput("slider2","slide",min=0,max=100,value=100,step=1,animate=TRUE))
),
mainPanel(
"abc"
)
)
))
server.R
shinyServer(function(input, output) {
}
)
You should probably use radioButtons()
instead, like so;
radioButtons(inputId="choice", label="What would you like to see?",
choices=c("red","green"))
This will let the user choose only one of the choices.
Note I fixed the quotes in the choices
part of this answer. Thanks to @Limbu for pointing out the typo.
You forgot to put quotation marks around each choice, you grouped the two choices as a single choice
radioButtons(inputId="choice", label="What would you like to see?",
choices=c("red","green"))
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