Skip to contents

Experimental. Observes a compatible Shiny shiny::ExtendedTask status function and maps its lifecycle to update_shad_button(). The task remains application-owned; this helper does not invoke the task, inspect its result, or create an async backend.

Usage

bind_shad_task_button(
  task,
  id,
  label_busy = "Processing...",
  label_success = NULL,
  label_error = NULL,
  session = shiny::getDefaultReactiveDomain()
)

Arguments

task

An object with a callable $status() member returning "initial", "running", "success", or "error".

id

Button input id.

label_busy

Label while the task is running.

label_success

Optional label after success.

label_error

Optional label after an error.

session

The Shiny session.

Value

Invisibly, the observer driving the binding.

Examples

if (interactive()) {
  ui <- page_shad(
    shad_button("Run report", inputId = "run"),
    shad_button("Finish", inputId = "finish", variant = "outline")
  )
  server <- function(input, output, session) {
    # Usually a shiny::ExtendedTask; any object with a $status() works.
    state <- shiny::reactiveVal("initial")
    task <- list(status = function() state())
    bind_shad_task_button(task, "run", label_success = "Done")
    shiny::observeEvent(input$run, state("running"))
    shiny::observeEvent(input$finish, state("success"))
  }
  shiny::shinyApp(ui, server)
}