Keep shiny app running in shiny server (no greying out)

I have deployed a shiny application with shiny server open source.

The app should not grey out as long as a user has the browser tab open. This is something people are not used to when interacting with websites.

So I set the app_idle_timeout option to 0. This seems to work, but now every 30 seconds a popup is opening for some millisesonds in the bottom left corner (It says 'Attempting to reconnect'). Is there a way to hide this popup because it is distracting?

1 Like

I'm curious if the websocket is timing out due to lack of traffic, so it restarts itself every 30s.

Try putting a "clock" or something on the page that updates frequently. This would constantly keep the page updating and traffic on the websocket.

It is strange and I do not know, why this timeouts happen. It does not matter if the user interacts with the app or does nothing. Every 30 seconds there is a disconnect.

I think I misunderstood the app_idle_timeout option as this does not have something to do with it, right? It only affects, what happens after a user closes the browser tab, or?

Based on a stackoverflow answer I added

  autoInvalidate <- reactiveTimer(10000)

But it does not help.

I believe that would keep the app thinking, but I believe you're losing the websocket connection between the app and the browser.

Mixed with your app_idle_timeout and the app below, I believe it should not quit.

ui <- fluidPage(
  "Am I losing connection?",
  tags$div(style = "position: absolute; top: -100px;",
server <- function(input, output) {
  output$clock <- renderText({
shinyApp(ui = ui, server = server)

The clock above will update every 5 seconds to a value that is above the window. This css prevents users from seeing the value, but since something is sent every 5 seconds, the websocket is kept alive.

Does this app show the timeout for you?

@barret Thanks, but it does not help. I think this issue is directly linked to the way I deployed the shiny server. I am running this as a Kubernetes Deployment in Google Cloud. An ingress with a https load balancer makes the app available to the outside. In the documentation in External Application Load Balancer overview  |  Load Balancing  |  Google Cloud I found that there is a 30 second timeout:

A configurable response timeout , which represents the amount of time the load balancer will wait for your backend to return a complete response.The default value is 30 seconds. Consider increasing this timeout under these circumstances:

  • If you expect a backend to take longer to return HTTP responses, or
  • If the connection is upgraded to a WebSocket.

When I change this timeout to 45 seconds, I will see the disconnects and reconnects after 45 seconds. So it's directly linked to this setting. But I still do not understand why do I loose the websocket connection between app and browser at all and what can be done to prevent this?

These are the configuration files of my ingress and service:

apiVersion: extensions/v1beta1
kind: Ingress
  name: shinyapp-ingress
  annotations: "my-ip"
  - secretName: sslcerts
    serviceName: shinyapp-service
    servicePort: 80

and for the service:

kind: Service
apiVersion: v1
  name: shinyapp-service
    app: shinyapp
  - protocol: TCP
    port: 80
    targetPort: 80
  type: NodePort
  sessionAffinity: ClientIP

@markusdumke I see this in their docs as well:

Maybe change it to 3600 (1 hr) in the Cloud config? Seeing the message once an hour isn't too bad.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.