Like shiny::reactiveVal(), but the setter also accepts a mirai or a
promise. The value updates when the task resolves. Setting a new task while
one is running supersedes the old one: a running mirai is cancelled and a
promise's result is ignored. Use mirai_async() to start the task so that
helper functions and reactive reads are captured as in reactiveAsync().
Value
A function of class "reactiveValAsync". Call it with no arguments
to read the value, or with one argument to set it. Errors from a failed
task are re-thrown on read.
Details
status_async() reports "initial" until the first task is set,
also when value was given, since no task has run.
Examples
if (interactive()) {
library(shiny)
server <- function(input, output, session) {
# Set from two places, so a reactiveVal rather than a reactive.
report <- reactiveValAsync()
observe({
report(mirai_async(build_report(input$region, input$month)))
}) |> bindEvent(input$generate)
observe(report(NULL)) |> bindEvent(input$clear)
output$report <- renderTable(report())
}
}
