Skip to contents

Swaps the palette's list contents for freshly rendered items and re-runs its filter. Use it for anything the session knows and the UI could not: recent documents, search hits, commands gated on the signed-in user.

Usage

update_shad_command(
  id,
  items,
  empty_text = "No results found.",
  session = shiny::getDefaultReactiveDomain()
)

Arguments

id

The palette's input id (namespaced automatically).

items

New items, in any form shad_command_palette() accepts.

empty_text

Text shown when nothing matches. It lives inside the list that is being replaced, so it has to be supplied again here.

session

The Shiny session.

Value

Invisibly NULL; called for its side effect.

Examples

if (interactive()) {
  ui <- page_shad(
    shad_command_palette("palette", items = c(Home = "home")),
    shad_switch("admin", "Admin mode")
  )
  server <- function(input, output, session) {
    shiny::observeEvent(input$admin, {
      items <- c(Home = "home")
      if (isTRUE(input$admin)) items <- c(items, Users = "users")
      update_shad_command("palette", items)
    })
  }
  shiny::shinyApp(ui, server)
}