Change the value of a radio group buttons input on the client
updateCheckboxGroupButtons(session, inputId, label = NULL, choices = NULL,
selected = NULL, status = "default", size = "normal",
checkIcon = list())
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 values 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.
# NOT RUN {
if (interactive()) {
library(shiny)
library(shinyWidgets)
# Example 1 ----
ui <- fluidPage(
radioButtons(inputId = "up", label = "Update button :", choices = c("All", "None")),
checkboxGroupButtons(
inputId = "btn", label = "Power :",
choices = c("Nuclear", "Hydro", "Solar", "Wind"),
selected = "Hydro"
),
verbatimTextOutput(outputId = "res")
)
server <- function(input,output, session){
observeEvent(input$up, {
if (input$up == "All"){
updateCheckboxGroupButtons(session, "btn", selected = c("Nuclear", "Hydro", "Solar", "Wind"))
} else {
updateCheckboxGroupButtons(session, "btn", selected = character(0))
}
}, ignoreInit = TRUE)
output$res <- renderPrint({
input$btn
})
}
shinyApp(ui = ui, server = server)
# Example 2 ----
library("shiny")
library("shinyWidgets")
ui <- fluidPage(
checkboxGroupButtons(
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 = TRUE
),
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))
updateCheckboxGroupButtons(
session = session, inputId = "somevalue",
choices = newchoices
)
updatePickerInput(
session = session, inputId = "updateselected",
choices = newchoices
)
})
observeEvent(input$updateselected, {
updateCheckboxGroupButtons(
session = session, inputId = "somevalue",
selected = input$updateselected
)
}, ignoreNULL = TRUE, ignoreInit = TRUE)
observeEvent(input$updatelabel, {
updateCheckboxGroupButtons(
session = session, inputId = "somevalue",
label = input$updatelabel
)
}, ignoreInit = TRUE)
}
shinyApp(ui = ui, server = server)
}
# }
Run the code above in your browser using DataLab