raistlin raistlin - 1 year ago 128
R Question

R Shiny - No initial value selected in radioButtons?

From the documentation:

radioButtons(inputId, label, choices, selected = NULL, inline = FALSE,
width = NULL)


selected The initially selected value (if not specified then defaults to the first value)

But, can you specify the
argument so that the rendered radioButtons has no initial value selected? The output of this initial value could be an empty string (
). In the example below, neither "a" nor "b" should be selected when the app is run.


ui = shinyUI(
radioButtons("test","test",choices=c("a","b"),selected = NULL),
), server = shinyServer(function(input, output,session) {
output$value <- renderText(input$test)


As sugested by Hackerman,
selected = character(0)
does the trick.

Answer Source

The problem with selected is that if not specified then defaults to the first value. But you can workaround this using the following:

selected = character(0)

Another way is providing a default option, like Nothing Selected

radioButtons("test","test",choices=c("Nothing Selected"="","a"="a","b"="b"),selected = NULL),
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download