ShinyManager身份验证屏幕没有超时

问题描述 投票:1回答:1

很抱歉再次提出这个问题,但我确实需要解决此问题(即将达到Shinyapps.io上的最大数据限制)。这是我先前的问题Previous Stack Question的链接这是我的演示应用程序的链接。 Demo App Hosted On ShinyApps.io您会注意到该应用程序没有超时。例如,这是我今天仅此应用程序的日志。 enter image description here

我已经尝试了上一个问题向我推荐的所有内容,并在timeOut函数中包含了shinymanager::secure_server()参数。

似乎是问题所在,shinyapps.io在UI上放置了一个不活动计时器。 UI处于非活动状态后,它将在R进程上启动超时。但是,在我们的情况下,UI直到身份验证才启动。这意味着我们的服务器保持运行状态。

诸如设置超时(setTimeout())之类的方法将是一个不错的选择。例如,如果用户未在5分钟内进行身份验证,则超时。我最初尝试了一个while循环,但没有按计划进行。

如果没有活动,我正在寻找一种使服务器超时的方法。这是我的代码的一个玩具示例。最后,这是github上Shinymanager软件包的链接。 shinymanager

Ui.R

ui <- dashboardPage(
   #My UI page and functions
 )
shinymanager::secure_app(ui)

Server.R

function(input, output, session){
 auth = secure_server(check_credentials = check_credentials(df)) #df is my client database

 observeEvent(auth$user,{
    #server functions. This only gets run once the user authenticates
  }

}
r shiny shinydashboard shinyjs
1个回答
1
投票

如果未输入凭据,此应用将在120秒后超时

library(shiny)
library(shinymanager)

inactivity <- "function idleTimer() {
var t = setTimeout(logout, 120000);
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, 120000);  // time is in milliseconds (1000 is 1 second)
}
}
idleTimer();"


# data.frame with credentials info
credentials <- data.frame(
  user = c("1", "fanny", "victor", "benoit"),
  password = c("1", "azerty", "12345", "azerty"),
  # comment = c("alsace", "auvergne", "bretagne"), %>% 
  stringsAsFactors = FALSE
)

ui <- secure_app(head_auth = tags$script(inactivity),
                 fluidPage(
                   # classic app
                   headerPanel('Iris k-means clustering'),
                   sidebarPanel(
                     selectInput('xcol', 'X Variable', names(iris)),
                     selectInput('ycol', 'Y Variable', names(iris),
                                 selected=names(iris)[[2]]),
                     numericInput('clusters', 'Cluster count', 3,
                                  min = 1, max = 9)
                   ),
                   mainPanel(
                     plotOutput('plot1'),
                     verbatimTextOutput("res_auth")
                   )

                 ))

server <- function(input, output, session) {

  result_auth <- secure_server(check_credentials = 
                                 check_credentials(credentials))

  output$res_auth <- renderPrint({
    reactiveValuesToList(result_auth)
  })

  # classic app
  selectedData <- reactive({
    iris[, c(input$xcol, input$ycol)]
  })

  clusters <- reactive({
    kmeans(selectedData(), input$clusters)
  })

  output$plot1 <- renderPlot({
    palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",
              "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))

    par(mar = c(5.1, 4.1, 0, 1))
    plot(selectedData(),
         col = clusters()$cluster,
         pch = 20, cex = 3)
    points(clusters()$centers, pch = 4, cex = 4, lwd = 4)
  })

}


shinyApp(ui = ui, server = server)
© www.soinside.com 2019 - 2024. All rights reserved.