I'm completely puzzled why two working lines of code (individually), which reset
a respective radiobutton
to empty (selected = character(0)
) only reset
the first line when put together inside 1 'observer'
this is the minimal example:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
tags$script("
Shiny.addCustomMessageHandler('resetValue', function(variableName) {
Shiny.onInputChange(variableName, null);
});
"),
radioButtons("radio","Click Me",choices = c("Choice 1","Choice s"),selected = character(0)),
radioButtons("radio2","Click Me",choices = c("Choice 1","Choice s"),selected = character(0)),
actionButton("clickMe","Click Me to Reset"),
actionButton("showValue", "Show value")
)
server <- function(input, output, session) {
observeEvent(input$clickMe,{
session$sendCustomMessage(type = "resetValue", message ='radio')
updateRadioButtons(session,"radio",choices = c("Choice 1","Choice s"),selected = character(0))
session$sendCustomMessage(type = "resetValue", message ='radio2')
updateRadioButtons(session,"radio2",choices = c("Choice 1","Choice s"),selected = character(0))
})
observeEvent(input$showValue, {
print(input$radio)
print(input$radio2)
})
}
shinyApp(ui, server)
where the sendcustomMessages
are used to reset
the values
, which is not achieved by selecting character(0)
, which comes from i.e. here