bind_task_button | R Documentation |
input_task_button
to ExtendedTask
Sets up a shiny::ExtendedTask to relay its state to an existing
input_task_button()
, so the task button stays in its "busy" state for as
long as the extended task is running.
Note that bind_task_button
does not automatically cause button presses to
invoke the extended task; you still need to use shiny::bindEvent()
(or
shiny::observeEvent()
) to cause the button press to trigger an invocation,
as in the example below.
bind_task_button
cannot be used to bind one task button to multiple
ExtendedTask
objects; if you attempt to do so, any bound ExtendedTask
that completes will cause the button to return to "ready" state.
bind_task_button(target, task_button_id, ...)
## Default S3 method:
bind_task_button(target, task_button_id, ...)
## S3 method for class 'ExtendedTask'
bind_task_button(target, task_button_id, ..., session = get_current_session())
target |
The target object (i.e. |
task_button_id |
A string matching the |
... |
Further arguments passed to other methods. |
session |
A Shiny session object (the default should almost always be used). |
The target
object that was passed in.
library(shiny)
library(bslib)
library(future)
plan(multisession)
ui <- page_sidebar(
sidebar = sidebar(
input_task_button("recalc", "Recalculate")
),
textOutput("outval")
)
server <- function(input, output) {
rand_task <- ExtendedTask$new(function() {
future({
# Slow operation goes here
Sys.sleep(2)
runif(1)
}, seed = TRUE)
})
# Make button state reflect task.
# If using R >=4.1, you can do this instead:
# rand_task <- ExtendedTask$new(...) |> bind_task_button("recalc")
bind_task_button(rand_task, "recalc")
observeEvent(input$recalc, {
rand_task$invoke()
})
output$outval <- renderText({
rand_task$result()
})
}
shinyApp(ui, server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.