roo*_*Joe 8 r shiny shiny-server shinydashboard
我在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;
}
}
~
Run Code Online (Sandbox Code Playgroud)
ism*_*gal 15
@PorkChop,感谢您的非常有用的回答!
为了完整起见,这里是@PorkChop 代码的稍微修改版本,它不会关闭浏览器选项卡,而是仅关闭会话并为用户留下一条消息:
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))
Run Code Online (Sandbox Code Playgroud)
这对到达这里非常有帮助。
Por*_*hop 11
您可以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))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4250 次 |
| 最近记录: |