Shiny server session time out doesn't work

后端 未结 3 1461
醉梦人生
醉梦人生 2020-12-02 19:54

I have a shiny app deployed on a Linux server. I want the app to timeout if there is no activity for a minute. Based on what I read, I added the line app_idle_timeout to th

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 19:59

    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))
    

提交回复
热议问题