Skip to contents

Sonner-style imperative toasts, driven from the server. Returns the toast id so you can later shad_toast_update() or shad_toast_dismiss() it (e.g. a loading toast that resolves to success).

Usage

shad_toast(
  message = NULL,
  title = NULL,
  description = NULL,
  variant = c("default", "success", "error", "warning", "loading"),
  duration = 5000,
  id = NULL,
  action_label = NULL,
  action_input = NULL,
  session = shiny::getDefaultReactiveDomain()
)

shad_toast_success(message, ...)

shad_toast_error(message, ...)

shad_toast_warning(message, ...)

shad_toast_loading(message, ...)

shad_toast_update(
  id,
  message = NULL,
  title = NULL,
  description = NULL,
  variant = NULL,
  duration = NULL,
  action_label = NULL,
  action_input = NULL,
  session = shiny::getDefaultReactiveDomain()
)

shad_toast_dismiss(id = NULL, session = shiny::getDefaultReactiveDomain())

Arguments

message

Main message text (used as the title if title is NULL).

title, description

Optional title / secondary line.

variant

One of "default", "success", "error", "warning", "loading". "loading" toasts never auto-dismiss until updated.

duration

Auto-dismiss delay in ms (default 5000).

id

Toast id. Generated if NULL.

action_label

Optional action-button label.

action_input

Input id set (to Date.now()) when the action is clicked, giving the server a reactive hook. Defaults to <id>_action.

session

The Shiny session.

...

Passed to shad_toast().

Value

The toast id (character), invisibly.

Details

Text is injected client-side via textContent; pass plain strings, not HTML. There is no R analogue of shad.toast.promise() – use the loading → shad_toast_update() flow instead.

Examples

if (interactive()) {
  ui <- page_shad(shad_button("Upload", inputId = "upload"))
  server <- function(input, output, session) {
    shiny::observeEvent(input$upload, {
      id <- shad_toast_loading("Uploading...")
      shad_toast_update(id, message = "Uploaded", variant = "success")
    })
  }
  shiny::shinyApp(ui, server)
}