| update_radio_button_Input | R Documentation |
Server-side companion to radio_button_Input(), mirroring
shiny::updateRadioButtons(). Use it to change the selected option, the
available choices, or the label of an existing radio button group from
within an observer, for example to keep a cookies settings radio in sync
with a choice the user made elsewhere.
update_radio_button_Input(
session = shiny::getDefaultReactiveDomain(),
inputId,
label = NULL,
choices = NULL,
selected = NULL,
inline = FALSE,
small = FALSE,
choiceNames = NULL,
choiceValues = NULL
)
session |
The |
inputId |
The id of the |
label |
New label for the input, or |
choices |
New vector of choices, or |
selected |
The value to select, or |
inline |
Whether the radios are inline. Only applies when |
small |
Whether to use the smaller radios. Only applies when |
choiceNames, choiceValues |
As in |
Only the arguments you supply are sent to the client; everything left at its
default of NULL is left untouched. Because it relies on
session$sendInputMessage(), the inputId is namespaced automatically when
called inside a Shiny module, so pass the unnamespaced id just as you would
to shiny::updateRadioButtons().
This function is deliberately agnostic about why you are updating the radio, which makes it a useful building block for packages that layer extra behaviour (such as analytics cookie consent) on top of shinyGovstyle. See the cookies and analytics vignette for an example of extending it.
Called for its side effect of sending a message to the client; no return value
radio_button_Input()
Other Govstyle select inputs:
button_Input(),
checkbox_Input(),
file_Input(),
radio_button_Input(),
select_Input()
ui <- shinyGovstyle::gov_page(
shinyjs::useShinyjs(),
shinyGovstyle::radio_button_Input(
inputId = "cookies",
label = "Do you want to accept analytics cookies?",
choices = c("Yes" = "yes", "No" = "no"),
selected = "no",
inline = TRUE
),
shinyGovstyle::button_Input(inputId = "accept", label = "Accept cookies")
)
server <- function(input, output, session) {
# Keep the radio in sync with a choice made elsewhere
shiny::observeEvent(input$accept, {
shinyGovstyle::update_radio_button_Input(
session,
inputId = "cookies",
selected = "yes"
)
})
}
if (interactive()) shinyApp(ui = ui, server = server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.