Selectize input - updating with the current value causes invalidation

892 views
Skip to first unread message

pvuto...@gmail.com

unread,
Jul 23, 2014, 10:11:44 AM7/23/14
to shiny-...@googlegroups.com
Hey guys,
I've got a single selectize input and an observer which updates the input whenever the user selects a value.
The update should do nothing - it sends a static list of choices and uses the current selection as the new selection.

However if the user quickly selects two values in a row, the value in the input object does not match the real value.
Hence, the update actually changes the selected value, which causes the observer to invalidate itself and run again.
Again, the input value is old, the selectize is changed, and the observer is thus stuck looping itself.

df.proto <- data.frame("publisher" = c(1:1000)) #the more values, the easier to reproduce the bug; works with about 50 too

shinyServer
(function(input, output, session){
  observe
({
   
print(paste0(">>>>> ENTERING OBSERVE input$publisher: ", paste(unlist(input$publisher), collapse = ", ")))    
   
    updateSelectizeInput
(session, "publisher", choices = df.proto$publisher, selected = input[["publisher"]])
   
   
print(paste0("EXITING OBSERVE input$publisher: ", paste(unlist(input$publisher), collapse = ", "), "<<<<<<"))
 
})

shinyUI
(
  navbarPage
("test",
             
    tabPanel
("Browse",
      fixedPage
(
        selectizeInput
("publisher", "publisher", choices = NULL, selected = NULL, multiple = T),
        HTML
("</br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br>")
     
)
   
)
 
)
)# End shiny.

I think the issue is caused by the huge list of choices - if I declare the choices in the UI and don't send them in the update call,
the bug is gone. In my production code, there are multiple selectizes which compute their respective choices based on each other,
and hence have to send these dynamic lists of possible choices using the update function, so this fix is not viable.

I'm trying to do something like updateSelectizeInput(choices = newChoices, selection = currentSelection). A user that clicks too fast
can cause the observer that the statement is in to loop on itself, which shouldn't happen as I'm not trying to change the current selection (currentSelection is always a subset of newChoices).

pvuto...@gmail.com

unread,
Jul 23, 2014, 10:29:39 AM7/23/14
to shiny-...@googlegroups.com
I miscopied server.R, it's missing the closing brackets. Again, this time properly:

server.R
df.proto <- data.frame("publisher" = c(1:1000)) #the more values, the easier to reproduce the bug; works with about 50 too

shinyServer
(function(input, output, session){
  observe
({
   
print(paste0(">>>>> ENTERING OBSERVE input$publisher: ", paste(unlist(input$publisher), collapse = ", ")))    
   
    updateSelectizeInput
(session, "publisher", choices = df.proto$publisher, selected = input[["publisher"]])
   
   
print(paste0("EXITING OBSERVE input$publisher: ", paste(unlist(input$publisher), collapse = ", "), "<<<<<<"))
 
})
}) # End server.

ui.R

Yihui Xie

unread,
Jul 24, 2014, 7:07:46 PM7/24/14
to pvuto...@gmail.com, shiny-discuss
Could you try the current development version?

devtools::install_github("shiny", "rstudio")

From my test, the devel version seems to be much faster than the
latest CRAN version 0.10.0. We plan to release the current devel
version as shiny 0.10.1 soon to CRAN, as you have probably seen in an
announcement earlier this week in this mailing list.

Regards,
Yihui

pvuto...@gmail.com

unread,
Jul 30, 2014, 8:03:52 AM7/30/14
to shiny-...@googlegroups.com
Thanks Yihui!

The new version no longer has the bug.

Yihui Xie

unread,
Aug 2, 2014, 12:05:25 AM8/2/14
to pvuto...@gmail.com, shiny-discuss
Thanks, and just FYI, shiny 0.10.1 is on CRAN now:
http://blog.rstudio.org/2014/08/01/shiny-0-10-1/

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