Selectize dropdown showing all items

2019-07-24 16:42发布

I have a small problem which I can't resolve. I suppose that the solution is very easy and I don't have a lot of knowledge in java language. Here is a small example:

library(shiny)

ui <- (fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput("userInput","Select User", c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21),
                  selected=1),
      selectInput("LongInput", "Long Strings", c("This is a long long string that is long.",
                                                 "This is a long long string that is longer."))
    ),

    # allows for long texts to not be wrapped, and sets width of drop-down
    tags$head(
      tags$style(HTML('
                      .selectize-input {
                      white-space: nowrap;
                      }
                      #LongInput + div>.selectize-dropdown{
                      width: 660px !important;
                      }
                      #userInput + div>.selectize-dropdown{
                                            width: 357px !important; maxItems: 21;
                      }
                      '
              )
      )
      )
      )
      ))

server <- function(input, output, session) {}

shinyApp(ui, server)

When the user clicks on the first selectInput in order to make a choice, instead of showing the first seven elements of the list, I would like to show all the elements of the list. Thanks.

2条回答
等我变得足够好
2楼-- · 2019-07-24 17:11

You could use css tags$style(type='text/css', ".selectize-dropdown-content {max-height: 1000px !important; }") to do that

Something like this:

ui <- (fluidPage(
  tags$style(type='text/css', ".selectize-dropdown-content {max-height: 1000px !important; }"), 
  sidebarLayout(
    sidebarPanel(
      selectInput("userInput","Select User", c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21),
                  selected=1),
      selectInput("LongInput", "Long Strings", c("This is a long long string that is long.",
                                                 "This is a long long string that is longer."))
    ),


    # allows for long texts to not be wrapped, and sets width of drop-down
    tags$head(
      tags$style(HTML('
                      .selectize-input {
                      white-space: nowrap;
                      }
                      #LongInput + div>.selectize-dropdown{
                      width: 660px !important;
   }
                      #userInput + div>.selectize-dropdown{
                      width: 357px !important; maxItems: 21;
                      }
                      '
      )
      )
      )
      )
      ))

You get:

enter image description here

查看更多
走好不送
3楼-- · 2019-07-24 17:32

I think shinyWidgets package is what you need. It has a pickerInput which will show all of the choices

#install.packages("shinyWidgets")
library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      pickerInput("userInput", label = "Select User", choices = 1:21, options = list(style = "btn-primary")),
      selectInput("LongInput", "Long Strings", c("This is a long long string that is long.",
                                                 "This is a long long string that is longer."))
    ),mainPanel()
  )
)

server <- function(input, output, session) {}

shinyApp(ui, server)

enter image description here

查看更多
登录 后发表回答