0

I have a Shiny app hosted in AWS. Now I want to define a Time-out option for my App, say as 5 min. Means, if a user is not active over the shiny app for more than 5 min then my App should get disconnected from the server.

Any idea which parameter to look for in the Shiny server config page?

Bogaso
  • 2,838
  • 3
  • 24
  • 54

1 Answers1

2

Since my answer havent been accepted here I will post it here. not that i used a small bit of JS to detect inactivity. You dont need the leaflet library as it is only a demo. The app will close the window after 5 secs

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))
Pork Chop
  • 28,528
  • 5
  • 63
  • 77