Using promise object in download handler in shiny R
Asked Answered
E

0

2

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?

Embolism answered 29/5, 2019 at 6:40 Comment(3)
I'd assign the future result to a reactiveVal via then and pass that reactiveVal to the downloadHandler.Demona
Hi...Thanks for the reply. I will try that. But i believe that all the reactives till the end has to be resolved as a promise object.Embolism
You might want to check this or thisDemona

© 2022 - 2024 — McMap. All rights reserved.