首页 > 解决方案 > 当 selectize=F 时在 selectInput() 中选择多个选项

问题描述

如何在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")
          
        )
    })
  }
)

标签: rshiny

解决方案


您所拥有的是允许多项选择。如果你添加verbatimTextOutput(outputId = "res")这个(即使它是临时的)你可能会看得更清楚uiOutput("box1")output$res <- renderPrint({input$`in`})output$box1server

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

在此处输入图像描述


推荐阅读