Search code examples
rwidgetshinyserver-sideselectize.js

R Shiny selectizeInput server side not initializing correctly


When trying to embed the selectize input widget in an Shiny application I ran into the following problem:

The item list isn't initialized with the complete list of items when using server = TRUE. Only after entering a character in the searchbox will the items appear. This is contrary to the behaviour when server = FALSE. In this case all items appear in the box initially (and this is the behaviour that I want). The reason that I want to use the server = TRUE option is that I want to be able to apply formatting to the items and this is not possible when generating the items client side. The example below reproduces the phenomenon with one selectize input using server = TRUE and the other with server = FALSE. In my opinion the behaviour should be the same in both cases.

Example app.R to reproduce the issue:

library(shiny)

server <- function(input, output, session) {
  updateSelectizeInput(session, 'cars1', server = TRUE, choices = rownames(mtcars))  
  updateSelectizeInput(session, 'cars2', server = FALSE, choices = rownames(mtcars))
}

ui <- fluidPage(
  selectizeInput('cars1', label = "server side", choices = NULL),
  selectizeInput('cars2', label = "client side", choices = NULL)  
  )

shinyApp(ui = ui, server = server)

Is this a bug or am I using the widget incorrectly? I am running R version 3.1.3 and Shiny 0.11.1 on Windows 7 64-bit.


Solution

  • This issue has been fixed in shiny v0.12.0 (on CRAN now). The server side selectizeInput() will load the first 1000 options initially (or the first n options when n < 1000).