Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple choice box in R/shiny - adding a scroll bar

Tags:

r

shiny

I build an R/shiny web app. I want to have a multiple choice box (I use checkboxGroupInput(), but am open to alternatives). However, the list of choices is long and I want to contain it in a relatively small box of options (that shows 5-6 options at a time) with a scroll bar that enables to scroll through the entire list of choices.

Is there a way this can be done? minimal example:

ui.R

library(shiny)
choices = paste("A",1:30,sep="_")

shinyUI(pageWithSidebar(

# Application title
headerPanel("my title"),
sidebarPanel(   
  checkboxGroupInput("inp", "choose any of the following", choices)
),
mainPanel(
   tableOutput("result")

)
))

server.R

library(shiny)
shinyServer(function(input, output) {
myInput <- reactive({
    input$inp
})
output$result <- renderTable({
x = myInput()
if(length(x)==0) {
x = "No Choice Made"
}
matrix(x,ncol=1)
})

})
like image 541
amit Avatar asked Mar 11 '13 20:03

amit


1 Answers

I found that using selectInput(..., multiple = TRUE) does the trick.

like image 113
amit Avatar answered Oct 01 '22 18:10

amit