Change the value of a radio group buttons input on the client
updateRadioGroupButtons(
session,
inputId,
label = NULL,
choices = NULL,
selected = NULL,
status = "default",
size = "normal",
checkIcon = list(),
choiceNames = NULL,
choiceValues = NULL
)
The session object passed to function given to shinyServer.
The id of the input object.
The label to set.
The new choices for the input.
The value selected.
Status, only used if choices is not NULL.
Size, only used if choices is not NULL.
Icon, only used if choices is not NULL.
List of names and values, an alternative to choices.
# NOT RUN {
if (interactive()) {
library("shiny")
library("shinyWidgets")
ui <- fluidPage(
radioGroupButtons(
inputId = "somevalue",
choices = c("A", "B", "C"),
label = "My label"
),
verbatimTextOutput(outputId = "res"),
actionButton(inputId = "updatechoices", label = "Random choices"),
pickerInput(
inputId = "updateselected", label = "Update selected:",
choices = c("A", "B", "C"), multiple = FALSE
),
textInput(inputId = "updatelabel", label = "Update label")
)
server <- function(input, output, session) {
output$res <- renderPrint({
input$somevalue
})
observeEvent(input$updatechoices, {
newchoices <- sample(letters, sample(2:6))
updateRadioGroupButtons(
session = session, inputId = "somevalue",
choices = newchoices
)
updatePickerInput(
session = session, inputId = "updateselected",
choices = newchoices
)
})
observeEvent(input$updateselected, {
updateRadioGroupButtons(
session = session, inputId = "somevalue",
selected = input$updateselected
)
}, ignoreNULL = TRUE, ignoreInit = TRUE)
observeEvent(input$updatelabel, {
updateRadioGroupButtons(
session = session, inputId = "somevalue",
label = input$updatelabel
)
}, ignoreInit = TRUE)
}
shinyApp(ui = ui, server = server)
}
# }
Run the code above in your browser using DataLab