R / shiny中的多选框 - 添加滚动条

时间:2021-02-16 20:35:11

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.

我构建了一个R /闪亮的Web应用程序。我想要一个多选框(我使用checkboxGroupInput(),但我可以选择其他选项)。但是,选项列表很长,我希望将它包含在一个相对较小的选项框中(一次显示5-6个选项),滚动条可以滚动整个选项列表。

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

})

1 个解决方案

#1


10  

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

我发现使用selectInput(...,multiple = TRUE)可以解决问题。

#1


10  

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

我发现使用selectInput(...,multiple = TRUE)可以解决问题。