SelectizeInput does not display all choices on shiny.io

安稳与你 提交于 2019-12-11 14:58:19

问题


I have a shiny app that has a selectizeInput widget which gets its about 26000 choices from a remote database in form of reactive data. The use of a remote database and reactivity is to avoid lagging and slowness when loading the choices. The issue is that when launched on the desktop locally, it works fine but when uploaded on shinyapps.io the widget does not present to the user all available choices. I have played around with the widgets attributes to no avail, for example, setting SERVER =TRUE and so on. I have put the code I am using below as well as a link to the data I want loaded to the selectizeInput as choices.

UI part

 library(shiny)
 library(DBI)
 library(RMySQL)
 library(shinydashboard)
 library(shinyjs)

 ui <- dashboardPage(  
     skin="yellow",  
   dashboardHeader(   ), 

  #sidebar content
   dashboardSidebar(
      sidebarMenu(  

          selectInput(
            inputId="selectData",
             label=" ", selected = NULL,
             choices=c( "title" )),      

       menuItem("Titles Search", tabName = "Titles", icon = icon("font"))

        )
       ),

     dashboardBody(

         tags$head(
        tags$style(HTML("
                  .content-wrapper {
                  background-color: green !important;
                  }

                  .main-header {
                  background-color: red !important;
                  }

                  "))

        ),

   tabItems(      
      tabItem(tabName = "Titles",              
            fluidRow(
               column(width=3,                        
                    box(                         
                      title=" ",
                       solidHeader=TRUE,
                        collapsible=TRUE,
                     width=NULL,
                     selectizeInput('titles', label = "Search by title", 
                choices = NULL, options = list(
                       placeholder = 'Type the title', maxOptions = 1000, 
                maxItems = 100,multiple = F, searchConjunction = 'and')),
                     tags$style(type="text/css",
                                ".selectize- 
        input::after{visibility:hidden;};"
                     )

                   )
                )
                )
             )                  
         )   
        )
        )

Server part

    library(shiny)
    library(DBI)
    library(RMySQL)
    library(shinydashboard)
    library(shinyjs)


      shinyServer(function(input, output, session) { 

        con <- dbConnect(MySQL(), user='XXXX', 
                 port = 3306, password='XXXXX', 
                 dbname='XXXXXX', 
                 host='XXXXXXXX' )
           query <- function(...) dbGetQuery(con, ...)
          on.exit(dbDisconnect(con), add = TRUE)



selectedData <- reactiveValues()

observeEvent(input$selectData, {

  con <- dbConnect(MySQL(), user='XXXXXX', port = 3306, password='XXXX', dbname='XXXXX', host='XXXXXXX' )
  query <- function(...) dbGetQuery(con, ...)
  on.exit(dbDisconnect(con), add = TRUE)

  if (input$selectData == "title") {
    selectedData$titledata <- query("SELECT titles FROM titles ;")
  }

  updateSelectizeInput(session, "titles",
                       choices =  as.character(unique(selectedData$titledata$titles)),
                       server = TRUE)
})

  session$onSessionEnded(function() { dbDisconnect(con) })

 })

What am I doing wrong? Is it a shinyapps.io problem or a coding issue?


回答1:


It looks like you are encountering a limit to the number of items selectize will load. You appear to load about 1000 items.

If you view the selectize documentation here, there is an option maxOptions that defaults to 1000. You even set this value equal to 1000 in your UI. Your default dataset contains 25k+ options.

  • Try raising this number to 30k.
  • Try adding this option to updateSelectizeInput in your server too.


来源:https://stackoverflow.com/questions/52728785/selectizeinput-does-not-display-all-choices-on-shiny-io

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