Update Shiny Inputs

Description

Change the value of a basecoat input from the server of a Shiny app. The page needs bc_shiny_deps() for these to have any effect.

Usage

bc_update_radio_group(id, value, session = shiny::getDefaultReactiveDomain())

bc_update_slider(id, value, session = shiny::getDefaultReactiveDomain())

bc_update_select(id, value, session = shiny::getDefaultReactiveDomain())

bc_update_combobox(id, value, session = shiny::getDefaultReactiveDomain())

bc_update_accordion(id, open, session = shiny::getDefaultReactiveDomain())

bc_update_dialog(id, open, session = shiny::getDefaultReactiveDomain())

bc_update_sidebar(id, open, session = shiny::getDefaultReactiveDomain())

bc_update_theme_switcher(id, mode, session = shiny::getDefaultReactiveDomain())

Arguments

Argument Description
id String. The ID of the input to update.
value The new value. A string for bc_radio_group(), a number for bc_slider(), and a character vector for bc_select() and bc_combobox().
session The Shiny session. Defaults to the current session.
open For bc_update_accordion(), a character vector of the IDs, or titles, of the items to open. Every other item is closed. Use character(0) to close them all. For bc_update_dialog(), a Bool: whether the bc_dialog(), bc_alert_dialog(), or bc_drawer() is open. For bc_update_sidebar(), a Bool: whether the bc_sidebar() is open.
mode String. "light" or "dark".

Value

NULL, invisibly.

Examples

if (interactive()) {
  library(shiny)

  ui <- bc_page_sidebar(
    bc_shiny_deps(),
    sidebar = bc_sidebar(id = "sidebar"),
    bc_switch("annual", "Pay annually"),
    bc_radio_group(
      name = "plan",
      bc_radio("monthly", "Monthly", checked = TRUE),
      bc_radio("yearly", "Yearly")
    )
  )

  server <- function(input, output, session) {
    observeEvent(input$annual, {
      bc_update_radio_group("plan", if (input$annual) "yearly" else "monthly")
    })
  }

  shinyApp(ui, server)
}