-
-
Save jcheng5/1283baec96c05a65778d931a8b7c7314 to your computer and use it in GitHub Desktop.
Attempt to use ExtendedTask + mirai with cancellation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(mirai) | |
library(promises) | |
library(bslib) | |
ui <- page_fluid( | |
input_task_button("go", "Go"), | |
actionButton("stop", "Stop"), | |
textOutput("out") | |
) | |
server <- function(input, output, session) { | |
mirai_obj <- NULL | |
task <- ExtendedTask$new(function() { | |
m <- mirai({ | |
Sys.sleep(5); | |
"hello, world" | |
}) | |
mirai_obj <<- m | |
m | |
}) |> bind_task_button("go") | |
observeEvent(input$go, { | |
task$invoke() | |
}) | |
observeEvent(input$stop, { | |
stop_mirai(mirai_obj) | |
}) | |
output$out <- renderText({ | |
task$result() | |
}) | |
observe({ | |
updateActionButton(session, "stop", disabled = !identical(task$status(), "running")) | |
}) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment