SelectizeInput does not display all choices on shi

2019-09-01 13:35发布

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条回答
来,给爷笑一个
2楼-- · 2019-09-01 14:26

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.
查看更多
登录 后发表回答