Reputation: 3318
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?
Upvotes: 0
Views: 1734
Reputation: 29407
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))
Upvotes: 2