我在AWS上托管了一个Shiny应用程序。现在,我想为我的应用程序定义一个超时选项,例如5分钟。意思是,如果用户未使用闪亮的应用程序超过5分钟,则我的应用程序应与服务器断开连接。
您知道要在Shiny服务器配置页面中查找哪个参数吗?
答案 0 :(得分:1)
由于我的答案尚未被接受here,因此我将在此处发布。不是我用了少量的JS
来检测不活动状态。您不需要leaflet
库,因为它只是一个演示。该应用将在5秒钟后关闭窗口
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))