Increasing the timeout for Shiny Server

Follow

Comments

3 comments

  • Jaclyn Patterson

    Hi Andrea,

    Thank you for providing this information. I am experiencing greyout of my app and the above code didnt work for me. The tags$head code ends in a comma, how is this integrated into the app code? Shiny now has an updated way to create apps where both the server and ui are in the same R script. This is outlined here(https://shiny.rstudio.com/articles/build.html) . Can you give a reproducible example of how to implement this fix above?

    Thanks very much,

    Michelle

    Submitted by: mmiron

    0
    Comment actions Permalink
  • Jaclyn Patterson

    Hi Michelle,

    I put together this working example with the Domino quick-start project (where the Shiny library is preloaded) to show the syntax for a combined ui and server file. In this case, tags$head and textOutput are being passed to sidebarPanel function, which is why they need to be followed with a comma.

    In my testing, this ran correctly and prevented the greyscreen timeout after 60 seconds.

    server <- function(input, output) {
      output$keepAlive <- renderText({                             ###
        req(input$count)                                           ###
        paste("keep alive ", input$count)                          ###
      })                                                           ##
      output$distPlot <- renderPlot({
        hist(rnorm(input$obs), col = 'darkgray', border = 'white')
      })
    }
    
    ui <- fluidPage(sidebarLayout(sidebarPanel(
      tags$head(                                                   ###vvv
        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>
          "
        )
      ),
      textOutput("keepAlive"),                                     ###^^^
      sliderInput(
        "obs", "Number of observations:", min = 10, max = 500, value = 100
      )
    ),
    
    mainPanel(plotOutput("distPlot"))))
    
    shinyApp(ui = ui, server = server)
    

    Submitted by: josh.mineroff

    0
    Comment actions Permalink
  • Jaclyn Patterson

    Thanks Josh! My app was no longer greying out, so I didn't need to try this, but I will keep it in mind for the future.

    Submitted by: mmiron

    0
    Comment actions Permalink

Please sign in to leave a comment.