Display all values in a Shiny selectInput box (1000+)

流过昼夜 提交于 2021-02-07 03:38:01

问题


I am working an a Shiny app where I want to allow the user to pick from a longer list of genes (~1800) and then have corresponding graphs for the selected gene displayed. My problem is that I cannot get Shiny to display the whole list of genes available to select from in the drop-down menu of the selectInput box, it seems that only the first 1000 or so get displayed.

Then I found a promising solution using server-side selectize, where all the available options get displayed when the user starts typing into the select box. However, when the user is not typing, the drop-down menu still doesn´t display more than the first 1000 genes, which can suggest that there are not more options available.

I recreated the problem with a different data set (1396 airport codes) for illustration purposes:

library(shiny)
library(nycflights13)

ui <- fluidPage(
  wellPanel(
    fluidRow(
      column(12, offset = 0,
        titlePanel("Look up airports"))),
    fluidRow(
      column(3, offset = 0,
        selectizeInput(inputId = "airportCode", label = "", choices = NULL,
          options = list(placeholder = "Type airport code"))))
  )
)

server <- function(input, output, session) {
  updateSelectizeInput(session, "airportCode",
    choices = as.vector(airports$faa), server = TRUE)
}

shinyApp(ui = ui, server = server)

When you don´t type into the select box, the last airport code displayed in the drop-down menu is only "PAM". Yet when you start typing you can get all the way down to the last one "ZYP", which I think this is rather confusing to the user.

Best would be to have all of the values appear in the drop-down menu, if that is somehow feasible. Otherwise have none at all listed there and have them only show up when you start typing.


回答1:


See https://github.com/rstudio/shiny/issues/412.

You can change the maximum number of options like so:

selectizeInput(inputId = "airportCode", label = "", choices = NULL,
  options = list(placeholder = "Type airport code",
    maxOptions = 2000)
  )


来源:https://stackoverflow.com/questions/40710947/display-all-values-in-a-shiny-selectinput-box-1000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!