shinyWidgets
shinyWidgets copied to clipboard
pickerInput doesn't notify shiny when calling `setValue` from JS
https://github.com/dreamRs/shinyWidgets/blob/5b3810d3e42ab885baecd5fe80480e8381758766/inst/assets/bootstrap-select/picker-bindings.js#L13-L16
In some situations updatePickerInput won't trigger input
to be updated. There should be a line at the end that notifies Shiny to set input. For example,
setValue: function setValue(el, value) {
$(el).val(value);
$(el).selectpicker("refresh");
Shiny.setInputValue(el.id, $(el).val());
}
Hello,
setValue
method is used to set value on the client side, not server side.
Can you provide an example where updatePickerInput()
fails to update input value ?
Victor
Indeed, when I check shiny's default widgets, they explicitly schedule callbacks.
What's weird is when I change their value via setValue
in JS, the corresponding inputs are also changed in R, that means eventually shiny callbacks are executed. However, setting values in pickerInput
via JS won't trigger updating the inputs in R.
I am having the same issue with pickerInput not updating correctly when deselecting all or using reset()
. Here is an example (please also check the input printed in the console).
library(shiny)
library(shinyjs)
ui = fluidPage(
div(
useShinyjs(),
id = "form",
pickerInput(
"letter",
"Pick a letter",
choices = LETTERS,
multiple = T,
selected = NULL,
options = list(`actions-box` = TRUE)
),
uiOutput("picker")
),
actionButton("resetAll", "Reset all")
)
server = function(input, output) {
Mydata <- reactive(data_frame(letters = input$letter))
output$picker <- renderUI({
textInput("text", "Click twice on Reset", value = input$letter)
})
observeEvent(input$resetAll, {
reset("form")
print(input$letter)
print(Mydata())
})
observeEvent(input$letter, {
print(input$letter)
print(Mydata())
})
}
shinyApp(ui, server)