0

I have created an app deployed on shinyapps.io.

From this app, I can click a button which triggers a call to an API written with plumber (deployed on AWS):

  observeEvent(input$button_clicked, {
    print("calculate called")
    res_calculate <- httr::POST(
        url = "http://myapi.amazonaws.com",
        path = "calculate",
        timeout(2400)
    )
    print("calculate returned")
})

On the API side, I have the following:

#' Get data from a data base, does a long calculation and returns the result 
#'
#' @export
#' 
#' @post /calculate
calculate <- function() {
    print("calculate started")
    # Here is a long calculation (~20 min)
    Sys.sleep(1200)
    res <- 1
    print("calculate ended")
    return(res)
}

When I click on the button, I get on the UI side "calculate called", on the logs of my API, I can see "calculate started" then 20 minutes pass and I get "calculate ended" but I never get "calculate returned" on the UI. Neither do I get a timeout error. Nothing. The Shiny app is kind of stuck for ever in a busy state.

I have shorter API calls from my Shiny app that go smoothly. (I will try to determine the time limit from which I get this problem.)

I am looking for hints on how to config httr:POSTso as to solve this problem.

vwrobel
  • 1,706
  • 15
  • 25
  • Shiny apps will timeout after like 5 mins I think... Could that be the issue? – Carl Boneri Oct 09 '19 at 12:40
  • No because I have increased this value from Shinyapps.io. – vwrobel Oct 09 '19 at 12:41
  • Actually I am currently running some tests. I am not sure but I think that the problem comes from observeEvent when the functin takes too long and not from the UI <-> API communication. – vwrobel Oct 09 '19 at 12:44
  • Instead of print why not use renderPrint and verbatimTextOutput for the flag? – Carl Boneri Oct 09 '19 at 13:10
  • Oh it was just a simplified version of my functions. `print`seemed more readable to submit on SO. So actually what I have noticed is the long call to the API from a Shiny app deployed locally is OK. The problem is when the POST is called from Shinyapps.io. By the way @CarlBoneri, the 5 min timeout you had in mind concerned Shinyapp.io ? – vwrobel Oct 09 '19 at 14:57
  • 1
    I run my own server, but https://docs.rstudio.com/shiny-server/#application-timeouts – Carl Boneri Oct 09 '19 at 15:46

0 Answers0