R Language Shiny Select box


Example

Create a select list that can be used to choose a single or multiple items from a list of values.

library(shiny)

ui <- fluidPage(    
  selectInput("id_selectInput", 
          label = HTML('<B><FONT size="3">What is your favorite color ?</FONT></B>'), 
          multiple = TRUE,
          choices = list("red" = "red", "green" = "green", "blue" = "blue", "yellow" = "yellow"), 
          selected = NULL),
  br(), br(),
  fluidRow(column(3, textOutput("text_choice")))) 


server <- function(input, output){
  output$text_choice <- renderPrint({
    return(input$id_selectInput)})
}

shinyApp(ui = ui, server = server)

enter image description here

It's possible to change the settings :

  • label : title
  • choices : selected values
  • selected : The initially selected value (NULL for no selection)
  • multiple : TRUE or FALSE
  • width
  • size
  • selectize: TRUE or FALSE (for use or not selectize.js, change the display)

It is also possible to add HTML.