gpt4 book ai didi

r - Shiny 的服务器 session 超时不起作用

转载 作者:行者123 更新时间:2023-12-04 05:17:23 30 4
gpt4 key购买 nike

我在 Linux 服务器上部署了一个 Shiny 的应用程序。如果一分钟没有事件,我希望应用程序超时。根据我阅读的内容,我将 app_idle_timeout 行添加到了 Shiny-server.conf 文件中,但我注意到它不起作用。有人可以建议我如何确保 session 在一分钟后超时吗?注意:我没有 Shiny 的服务器 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;

}
}
~

最佳答案

您可以配置您的 idle内时间shiny像这样使用一些 JS 的应用程序,这里应用程序将在 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))

关于r - Shiny 的服务器 session 超时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33839543/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com