我在Linux服务器上部署了一个闪亮的应用程序。如果一分钟没有活动,我希望应用程序超时。根据我读到的内容,我将行app_idle_timeout添加到shiny-server.conf文件中,但我注意到它不起作用。有人可以建议我如何确保会话在一分钟后超时?注意:我没有闪亮的服务器PRO。
下面是我的shiny-server.conf的样子。
Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;
# 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;
app_idle_timeout 60;
# 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;
}
}
~
答案 0 :(得分:11)
您可以使用某些JS在idle
应用中配置shiny
时间,这样应用会在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))
答案 1 :(得分:2)
开源闪亮服务器上没有会话超时功能。它仅作为专业版的一部分。
答案 2 :(得分:2)
@Pork Chop,非常感谢您的有用回答!
仅出于完整性考虑,以下是@Pork Chop代码的稍微修改后的版本,它不会关闭浏览器选项卡,而是仅关闭会话并为用户留下一条消息:
library(shiny)
library(leaflet)
timeoutSeconds <- 5
inactivity <- sprintf("function idleTimer() {
var t = setTimeout(logout, %s);
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() {
Shiny.setInputValue('timeOut', '%ss')
}
function resetTimer() {
clearTimeout(t);
t = setTimeout(logout, %s); // time is in milliseconds (1000 is 1 second)
}
}
idleTimer();", timeoutSeconds*1000, timeoutSeconds, timeoutSeconds*1000)
ui <- fluidPage(
tags$script(inactivity),
leafletOutput("mymap")
)
server <- shinyServer(function(input,output,session){
observeEvent(input$timeOut, {
print(paste0("Session (", session$token, ") timed out at: ", Sys.time()))
showModal(modalDialog(
title = "Timeout",
paste("Session timeout due to", input$timeOut, "inactivity -", Sys.time()),
footer = NULL
))
session$close()
})
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))
This对到达这里很有帮助。