Shiny provides a selectizeInput
that wraps selectize.js
, which produces a text input / combo box widget. There are several reasons that I'd like to delay loading of the options/values for the selectizeInput: there may be a long list of values or the possible values are dependent on other parameters. Also, I'd like the user to be able to create new values (e.g. choose an existing value or create your own).
But in all of these cases, the value of the selectizeInput cannot be bookmarked using Shiny's server-side bookmarking. When the selectizeInput object is initialized, the bookmarked value stored in the input
are not yet valid option values.
Does anybody have any clever workarounds to bookmark selectizeInput values?
Here's the simplest example dealing with just the create
option:
library(shiny)
ui <- function(request) {
fluidPage(
selectizeInput("foo", "Created Values Cannot Be Bookmarked", choices=c("Choose From List or Type New Value"="", "bar", "baz"),
options=list(create=TRUE)),
bookmarkButton("Update URL")
)}
server <- function(input, output) {
onBookmarked(function(url) {
updateQueryString(url)
})
}
shinyApp(ui = ui, server = server, enableBookmarking = "server")
If you type a new value in the selection box, hit the bookmark button to update the URL in the location bar in the browser, and hit reload, then that created value will be lost. Try the same with an existing option and it works, of course.
It gets more complicated if option loading is delayed, but the problem is the same, which is that the user's selection is not valid when the selectizeInput
is rendering.