有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Selectize下拉列表显示所有项目

我有个小问题不能解决。我认为这个解决方案非常简单,而且我对java语言没有太多的知识。 下面是一个小例子:

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)

当用户单击第一个selectInput进行选择时,我希望显示列表的所有元素,而不是显示列表的前七个元素。 谢谢


共 (2) 个答案

  1. # 1 楼答案

    我认为shinyWidgets包是您所需要的。它有一个pickerInput将显示所有选项

    #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

  2. # 2 楼答案

    您可以使用csstags$style(type='text/css', ".selectize-dropdown-content {max-height: 1000px !important; }")来实现这一点

    大概是这样的:

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

    你会得到:

    enter image description here