server-side selectizeInput doesn't work properly

2,286 views
Skip to first unread message

Adomas Budrys

unread,
Aug 6, 2014, 10:33:08 AM8/6/14
to shiny-...@googlegroups.com
Hi, 

I am trying to reproduce simple example of server-side selectizeInput, however it doesn't work for me properly.
I am using example here http://shiny.rstudio.com/articles/selectize.html and my code is:

ui.R:

shinyUI(fluidPage(
  selectizeInput("quality", label="Quality level",choices= NULL, multiple = TRUE)
))

server.R:

shinyServer(function(input, output, session) {
  updateSelectizeInput(session, "quality", choices = c("moderate 1","moderate 2","moderate 3","bad 1","bad 2","good 1","good 2","good 3"), server = TRUE)
})

If I set server = FALSE , it works as it should be - from client-side. 

Then I tried other example provided: http://shiny.rstudio.com/gallery/option-groups-for-server-side-selectize.html which works perfectly.

However, I couldn't figure out why server-side selectize doesn't work with single array of strings.

Thanks for any help,

Adomas

Marco Blanchette

unread,
Aug 8, 2014, 3:47:44 PM8/8/14
to shiny-...@googlegroups.com
Same thing here... I have production apps that stop working... they do not render selection upon entry from server side any more... 

Also, the githup shiny repos breaks upon loading... Can we fix this quick quick...

thanks
 
My version of an app

### ui.R
library(shiny)

shinyUI(fluidPage(
    selectizeInput('geneID',
                   label="Type or select your genes:",
                   choices=c("Genes"=""))
    ))

### server.R
library(shiny)

shinyServer(function(input, output, session) {
    data <- as.vector(sapply(LETTERS[1:5],paste,1:5,sep="."))
    updateSelectizeInput(session, 'geneID', choices = data, server = TRUE)
})

Adomas Budrys

unread,
Aug 11, 2014, 1:45:55 AM8/11/14
to shiny-...@googlegroups.com
So, after some time, I finally figured it out.

You have to make a data frame, with two columns with names: value and label and then pass it to selectizeInput. 
In this case you can search in the selectizeInput with labels and when you select them, they will return values. 

This easy example will explain everything:

#### server.R

shinyServer(function(input, output, session) {

  d <- c("moderate 1","moderate 2","moderate 3","bad 1","bad 2","good 1","good 2","good 3")
  data <- data.frame(value=d, label=d)
  updateSelectizeInput(session, 'group', choices = data, server = TRUE)

  output$values <- renderText({
    input$group
  })
})

##### ui.R

shinyUI(fluidPage(
  selectizeInput('group', NULL, NULL, multiple = TRUE),
  uiOutput("values")
))

msquatrito

unread,
Aug 11, 2014, 4:03:48 AM8/11/14
to shiny-...@googlegroups.com

I had similar issues with the selectize input on the server side that had stopped working last week.
Yihui Xie said that it is a known bug and recommend to update shiny with the latest development version.
After the update my apps and your examples are working fine. I hope it solves your problem as well.
Best
Massimo

Alex Rowe

unread,
Aug 19, 2014, 6:14:46 AM8/19/14
to shiny-...@googlegroups.com
Thanks Adomas for that! Now adding 17000 gene names to a selectizeInput doesn't crash on ShinyApps.io

I have spent several hours trying to figure out why the updateSelectizeInput worked fine with server=FALSE, but was blank (with no error logs) with server=TRUE.

I admit to only having skim-read the shiny reference, but I wonder whether it would be worth updating Yihui's selectizeInput article - http://shiny.rstudio.com/articles/selectize.html
to make it unambiguously clear that the choices have to be in a data frame (or named character vector ) only.  --- Do I need to post this elsewhere, of will Yihui see it here?

The current text  regarding server-side selectize (below) led me to assume that my unnamed character vector was a valid "arbitrary R data object".

"Here data can be an arbitrary R data object, such as a (named) character vector, or a data frame. Note the client-side selectize can only accept a character vector for the choices argument."

Regards,

Alex

Yihui Xie

unread,
Sep 2, 2014, 11:05:28 PM9/2/14
to Alex Rowe, shiny-discuss, Adomas Budrys, msquatrito, Marco Blanchette
I think it was a bug that I fixed immediately after we released shiny
0.10.1 to CRAN (sorry for not noticing it earlier):
https://github.com/rstudio/shiny/issues/557

A single unnamed character vector should work for "choices". For now,
you can install the development version of shiny from Github:

devtools::install_github(c('rstudio/htmltools', 'rstudio/shiny'))

I just tested your original example, and it worked fine. Thanks for the report!

Regards,
Yihui
Reply all
Reply to author
Forward
0 new messages