Thanks for developing shiny.worker. I'm trying to use shiny.worker to handle downloads asynchronously. I'm aware that it's possible with future, but I'd like to be able to try this using shiny.worker. The scenario is that I'd like the renderText to update while a download is occurring in the background. I've placed the write.csv with Sys.sleep(10) within the worker$run_job to simulate a long-running process that I'd like to delegate to the background. However, there are two things that I think are wrong with this code, and I don't know how to approach them:
- I don't think
write.csv(mtcars, file) is able to find the file arg in the parent content = function(file) environment
- It's not clear what I should specify in the
args_reactive arg of worker$run_job given that it's a download button with no input$...
My minimal reprex is below:
library(shiny.worker)
worker <- initialize_worker()
ui <- fluidPage(
downloadButton("download", "Download"),
numericInput("count",
NULL,
1,
step = 1),
textOutput("text")
)
server <- function(input, output, session) {
output$text <- renderText({
paste(input$count)
})
output$download <- downloadHandler(
filename = "data.csv",
content = function(file) {
worker$run_job("test", function(file = file) {
temp <- setwd(tempdir())
on.exit(setwd(temp))
Sys.sleep(10)
write.csv(mtcars, file)
}
)
}
shinyApp(ui, server)
Thanks for developing
shiny.worker. I'm trying to useshiny.workerto handle downloads asynchronously. I'm aware that it's possible withfuture, but I'd like to be able to try this usingshiny.worker. The scenario is that I'd like therenderTextto update while a download is occurring in the background. I've placed thewrite.csvwithSys.sleep(10)within theworker$run_jobto simulate a long-running process that I'd like to delegate to the background. However, there are two things that I think are wrong with this code, and I don't know how to approach them:write.csv(mtcars, file)is able to find thefilearg in the parentcontent = function(file)environmentargs_reactivearg ofworker$run_jobgiven that it's a download button with noinput$...My minimal reprex is below: