I have been trying to use Futures library in my Shiny code in order to make a particular task asynchronous, which is time taking. The promise handler of this Future object works well in reactive, eventReactive and observeEvent. But when it comes to download handler , it is not working and giving me an error.
The code is as follows. I place the task which is time taking inside the Future.
futureData <- eventReactive(input$generateButton, {
p <- Progress$new(session, min = 0, max = 100)
p$set(value = 20, message = "Fetching data",detail = "This might take a while...")
pwd <- getwd()
future({
setwd(pwd)
generateReport()
}) %>% finally({~p$set(value=100);~p$close()}) %...!%
(function(error) {
print(paste("Unexpected error: ",error,error$message))
})
})
pptData <- eventReactive(futureData(), {
futureData() %...>% {
futureData <- .
# Build Report Naming Convention
pptId <- paste(futureData$pptTitle, gsub(":", "-", Sys.time()),sep = "_")
pptFlName <- paste(pptId, ".pptx", sep = "")
pptFile <- paste("Reports/", pptFlName, sep = "")
return(list(
"pptId"= pptId,
"pptFlName"= pptFlName,
"pptFile"= pptFile
))
}
})
# Download handler on a button click
output$downloadwb <- downloadHandler(
filename = pptData() %...>% `[[`("wbFlName"),
content = function(file) {
file.copy(pptData() %...>% `[[`("wbFile"), file)
})
I get the following error:
Warning: Error in enc2utf8: argument is not a character vector [No stack trace available]
Could you please help me wit this? Has anyone tried using promise object inside download handler in Shiny?
reactiveVal
viathen
and pass thatreactiveVal
to thedownloadHandler
. – Demona