Replace a command palette's items from the server
Source:R/command-palette.R
update_shad_command.RdSwaps 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.
See also
Other shadshiny server API:
bind_shad_task_button(),
shad_message_scroller_to_bottom(),
shad_overlay_server,
shad_remove_dialog(),
shad_show_dialog(),
shad_toast(),
update_shad
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)
}