Mark White
Mark White

Reputation: 1496

Using shiny::runApp in Dockerfile and issues with timeout

I have a Shiny app in a Docker container deployed to AWS.

I unfortunately cannot provide a fully reproducible example given that there are many moving pieces here with the app.R file, the app connecting to our SQL database, information to connect to AWS, etc.

However, the Dockerfile installs all the necessary dependencies and ends with running the Shiny app via Rscript that just does shiny::runApp('.', host='0.0.0.0', port=8080).

This deploys just fine, and I can access it via the web address in which it was assigned.

However, if a user ever switches to a new window, changes tabs for too long, or leaves it idle for too long, the app times out and does the familiar "graying-out" that Shiny apps do.

Is there a way to prevent this from happening when I do shiny::runApp()? I do not find any timeout arguments in the documentation.

Upvotes: 1

Views: 997

Answers (1)

Anja F.
Anja F.

Reputation: 76

Context: Shiny uses a websocket (RFC 6455) for its constant client-server communication. If, for whatever reason, this websocket connection gets dicsonnected, the user experience is the described "greying out". Depending on your setup, there are multiple possibilities why this happens, where one option is the most likely: There is a proxy or load balancer that has an unexpected http time out value set.

Answer: From our own setup, standalone Shiny app (no shiny-server involved) using Kubernetes and nginx-ingress, the default settings allowed for lingering connections for up to 60 seconds. We were able to manipulate this behaviour by adding the following annotations to our manifest:

kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-read-timeout: '3600'
    nginx.ingress.kubernetes.io/proxy-send-timeout: '3600'

Mind you, depending on your configuration there could be more proxies involved which might complicate things (don't ask me how I know...).

Alternatively you can try to prevent any timeout by adding a heartbeat mechanism to the Shiny application. Some ways of doing this are discussed in this issue on GitHub.

Upvotes: 2

Related Questions