You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can someone provide an example of ExtendedTask in a simple shiny app? Any example would be helpful, even if it doesn't match the example code below.
library(shiny)
ui <- fluidPage(
titlePanel("Async Operation with ExtendedTask"),
actionButton("start_btn", "Start Long Operation"),
verbatimTextOutput("status"),
verbatimTextOutput("result")
)
server <- function(input, output, session) {
# Define the async function
longOperation <- function() {
Sys.sleep(5) # Simulate a time-consuming task
runif(1, 0, 100) # Return a random number as the result
}
# Create the ExtendedTask
myTask <- ExtendedTask$new(func = longOperation)
observeEvent(input$start_btn, {
myTask$invoke() # Start the operation
})
output$status <- renderText({
myTask$status()
})
output$result <- renderText({
req(myTask$result()) # Use req to wait for the result
paste("Operation result:", myTask$result())
})
}
shinyApp(ui, server)
The text was updated successfully, but these errors were encountered:
Can someone provide an example of ExtendedTask in a simple shiny app? Any example would be helpful, even if it doesn't match the example code below.
The text was updated successfully, but these errors were encountered: