Skip to contents

Methods for bslib::bind_task_button() so that a bslib::input_task_button() shows its busy state while the task of a reactiveAsync(), observeAsync() or reactiveValAsync() is "running" and returns to ready when it settles or is cancelled, as it does for an ExtendedTask. Binding reads the task status without starting a reactiveAsync() that nothing has read yet.

Usage

# S3 method for class 'reactiveAsync'
bind_task_button(
  target,
  task_button_id,
  ...,
  session = shiny::getDefaultReactiveDomain()
)

# S3 method for class 'observeAsync'
bind_task_button(
  target,
  task_button_id,
  ...,
  session = shiny::getDefaultReactiveDomain()
)

# S3 method for class 'reactiveValAsync'
bind_task_button(
  target,
  task_button_id,
  ...,
  session = shiny::getDefaultReactiveDomain()
)

Arguments

target

An object created by reactiveAsync(), observeAsync() or reactiveValAsync().

task_button_id

The id of the bslib::input_task_button().

...

Ignored.

session

The Shiny session.

Value

target, invisibly, so the call can be piped like bindEvent().

Examples

if (interactive()) {
  library(shiny)
  library(bslib)
  ui <- page_fluid(
    selectInput("spot", "Spot", c("Muizenberg", "Kommetjie")),
    input_task_button("go", "Simulate"),
    plotOutput("band")
  )
  server <- function(input, output, session) {
    sim <- reactiveAsync(simulate_band(input$spot)) |>
      bindEvent(input$go) |>
      bind_task_button("go")
    output$band <- renderPlot(plot(sim()))
  }
  shinyApp(ui, server)
}