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).