Select multiple choices in selectInput() when selectize=F

Viewed 27

How can I select multiple items in selectInput() when selectize=F?

library(shiny)
library(shinydashboard)
shinyApp(
  ui = dashboardPage(
    header = dashboardHeader(),
    sidebar = dashboardSidebar(),
    body = dashboardBody(
      uiOutput("box1")

    ),
    title = "DashboardPage"
  ),
  server = function(input, output) {
    output$box1<-renderUI({

        box(

          selectInput(inputId = "in", label = "Choose", choices = c('Short','A very short sentence.'), 
                      selectize = F,multiple=T, size = 5, width = "150px")
          
        )
    })
  }
)
1 Answers

What you have is allowing multiple selections. You may see it more clearly if you add this (even if it's temporary) Add verbatimTextOutput(outputId = "res") after the uiOutput("box1") (don't forget to add a comma) and add output$res <- renderPrint({input$`in`}) after output$box1 in server

library(shiny)
library(shinydashboard)
shinyApp(
  ui = dashboardPage(
    header = dashboardHeader(),
    sidebar = dashboardSidebar(),
    body = dashboardBody(
      uiOutput("box1"),                       # comma added here
      verbatimTextOutput(outputId = "res")    # this is added
    ),
    title = "DashboardPage"
  ),
  server = function(input, output) {
    output$box1 <- renderUI({
      box(
        selectInput(inputId = "in", label = "Choose", choices = c('Short','A very short sentence.'), 
                    selectize = F,multiple=T, size = 5, width = "150px")
      )# ends the box
    }) # ends output$box1
    output$res <- renderPrint({input$`in`})  # this is added here - since 'in' is a keyword I would suggest a different id...
  } # ends server call
) # ends shinyApp

enter image description here

Related