Updating Shiny Server Config to Change Timeout Error

Updating Shiny Server Config to change timeout error

Fixed it using this SO answer User session is getting interrupted after approx. 45 seconds

I was putting the http_keepalive_timeout function in the wrong place. Please see below for the correct shiny-server.conf update:

# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;
http_keepalive_timeout 180;

# Define a server that listens on port 3838
server {
listen 3838;

# Define a location at the base URL
location / {

# Host the directory of Shiny Apps stored in this directory
site_dir /srv/shiny-server;

# Log all Shiny output to files in this directory
log_dir /var/log/shiny-server;

# When a user visits the base URL rather than a particular application,
# an index of the applications available in this directory will be shown.
directory_index on;

}
}

Shiny server session time out doesn't work

You can configure your idle time within the shiny app like so using some JS, here the app will timeout after 5 seconds.

library(shiny)
library(leaflet)

inactivity <- "function idleTimer() {
var t = setTimeout(logout, 5000);
window.onmousemove = resetTimer; // catches mouse movements
window.onmousedown = resetTimer; // catches mouse movements
window.onclick = resetTimer; // catches mouse clicks
window.onscroll = resetTimer; // catches scrolling
window.onkeypress = resetTimer; //catches keyboard actions

function logout() {
window.close(); //close the window
}

function resetTimer() {
clearTimeout(t);
t = setTimeout(logout, 5000); // time is in milliseconds (1000 is 1 second)
}
}
idleTimer();"

ui <- fluidPage(
tags$script(inactivity),
leafletOutput("mymap")

)

server <- shinyServer(function(input,output,session){

points <- eventReactive(input$recalc, {
cbind(rnorm(40) * 2 + 13, rnorm(40) + 48)
}, ignoreNULL = FALSE)

output$mymap <- renderLeaflet({
leaflet() %>%
addProviderTiles(providers$Stamen.TonerLite,options = providerTileOptions(noWrap = TRUE)) %>%
addMarkers(data = points())
})

})
runApp(list(ui = ui, server = server))

User session is getting interrupted after approx. 45 seconds

Well, after searching and trying out different options I was able to find the answers to my questions.

  1. The user session was getting interrupted around approximately 45 seconds every single time because the http_keepalive_timeout parameter was not defined in the server configuration and the default value for http_keepalive_timeout parameter is 45 seconds.
  2. To prevent the session from getting reaped before the report generation, I added the http_keepalive_timeout parameter to the shiny-server.conf at the top level and set it's value to 120 seconds as shown below.

    http_keepalive_timeout 120;

You can set the http_keepalive_timeout value as per your wish. I set it to 120 as my application is taking around 100-110 seconds to generate the report.

Reference: shiny server configuration
Sample Image



Related Topics



Leave a reply



Submit