Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allowing one tick only in checkboxGroupInput

Tags:

r

shiny

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) {

}
)
like image 517
Rajarshi Bhadra Avatar asked Dec 22 '14 17:12

Rajarshi Bhadra


2 Answers

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.

like image 88
John Paul Avatar answered Nov 15 '22 05:11

John Paul


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"))
like image 35
Limbu Avatar answered Nov 15 '22 06:11

Limbu