Reset radio buttons in shiny, updateRadioButtons(selected = character( 0)) not working

Viewed 203

I`m trying to reset the radio buttons to the initial empty state with updateRadioButtons(). The documentation of this function says:

Similarly, for these inputs, the selected item can be cleared by using selected=character(0).

These instructions work when creating the buttons in the ui but, as you can see in the example below, it doesn´t work when using updateRadioButtons(). I`ve already try ( in both ends) :

  • selected = NULL
  • selected = FALSE
  • selected = ""

Any idea why this isn´t working ?

Thanks in advance !

library(shiny)

ui <- fluidPage(

            radioButtons("radbut","Pick one:",
                         choices = LETTERS[1:6],
                         inline = T,
                         selected = character(0)
                         ),
            actionButton("reset",label = "Reset Radio"),
            verbatimTextOutput("radio_sel")
)

server <- function(session,input, output) {

    output$radio_sel <- renderPrint(input$radbut)
    
    observeEvent(input$reset,{
        print("reseting..")
        updateRadioButtons(session,"radbut",selected = character(0))
        print("Done")
    })
}

shinyApp(ui = ui, server = server)
0 Answers
Related