0

I am trying to use promises/future in a code block that is taking too long in my shiny app. The problem is that i am using the httr package inside a loop to retrieve data, and this is the only way i can get data from the api. The problem is that i know that i can't use reactive/input values inside the future, but when i use the future in diferent parts of the code, nothing happen.

This is the code, the df is an empty dataframe with just the columns

          for (i in 1:1000){
            url<-glue("{api_domain}stats/conversions?date_from={input$date_start_conversions}&date_to={input$date_final_conversions}&offer={input$offer_id_conversions}&limit=5000&page={i}")
            api_token<-Sys.getenv('API_TOKEN')
            r = GET(url,add_headers("API-KEY"=api_token))
            raw_response <- content(r, as="text") 
            json <- fromJSON(raw_response)
            df_query<-as.data.frame(json$conversions) 
            df <- rbind(df, df_query) 
            if (nrow(df_query)==0) break 
            df
          }
          })
Hermit97
  • 1
  • 1
  • Can you pre-fetch the data? – Bruno May 29 '20 at 15:26
  • What do you mean by pre-fetch the data? – Hermit97 May 29 '20 at 17:11
  • Like doing the httr before the application goes live and storing it somewhere faster – Bruno May 29 '20 at 19:15
  • I described two approaches to this scenario [here](https://stackoverflow.com/a/56271375/9841389). 1. create a future (or 2nd R process) that writes the result of each iteration to a file and read the changes back in using `reactiveFileReader` or 2. set up inter process communication via `library(ipc)`. – ismirsehregal Jun 02 '20 at 13:44

0 Answers0