Increasing the timeout for Shiny Server

When accessing your published Shiny Server, the app will timeout after the default setting of 60 seconds of inactivity. If you need to increase this timeout then there are two ways to increase the timeout:

1)  If your team has a Shiny Server Pro license then you could set this up within your Domino installation. If you have a license and need assistance, please reach out to our support team. Once you are using Shiny Server Pro you can increase the timeout using the following guide:

http://docs.rstudio.com/shiny-server/#application-timeouts

2) If you are using Shiny Server (non-pro version) then the following workaround may be useful for you. The following workaround allows the app to send data back and forth through the WebSocket every 55 seconds, keeping the connection open. The following code snippets will need to be included with your Shiny app.

In the UI, add the following code:

tags$head(
        HTML(
          "
          <script>
          var socket_timeout_interval
          var n = 0
          $(document).on('shiny:connected', function(event) {
          socket_timeout_interval = setInterval(function(){
          Shiny.onInputChange('count', n++)
          }, 15000)
          });
          $(document).on('shiny:disconnected', function(event) {
          clearInterval(socket_timeout_interval)
          });
          </script>
          "
        )
        ),

Next, add the following line anywhere after the previous script in the same UI file:

textOutput("keepAlive")

And within the server file, add:

output$keepAlive <- renderText({
      req(input$count)
      paste("keep alive ", input$count)
    })

Once these changes have been made, start your Shiny app and ensure it publishes without errors. The app timeout duration should utilize your new configuration.

Was this article helpful?
1 out of 1 found this helpful