请看下面的代码。我在安全页面下运行闪亮的应用程序时遇到了问题。当我登录我的帐户时,“onSessionEnded”函数会被触发一次。然后当我关闭应用程序时它会再次触发。
你知道如何让我登录账户时不触发“onSessionEnded”吗?理想情况下,“onSessionEnded”应该仅在应用程序关闭时触发,对吗?有人可以给我一些建议吗?
您可以使用用户名:
a
和密码:a
直接运行代码
library(shiny)
library(shinymanager)
credentials <- data.frame(
user = c("a", "b"),
password = c("a", "b"),
stringsAsFactors = FALSE
)
ui <- fluidPage(
verbatimTextOutput("auth_output")
)
ui <- secure_app(ui)
lang <- shinymanager:::language$new()
lang$add(
"Please authenticate" = "Test Page",
"Username:" = "Username:",
"Password:" = "Password:",
"Login" = "Sign in"
)
server <- function(input, output, session) {
res_auth <- secure_server(
check_credentials = check_credentials(credentials)
)
output$auth_output <- renderPrint({
reactiveValuesToList(res_auth)
})
session$onSessionEnded(function() {
print("onSessionEnded Run!!!")
})
}
shinyApp(ui, server)
我没有代表对你的帖子发表评论,但我相信这个问题可以通过其他 stackoverflow 帖子来回答/解决。
Shiny 服务器 - 如何使用 session$onSessionEnded()
因为它可能应该在您的代码中实现:
library(shiny)
library(shinymanager)
credentials <- data.frame(
user = c("a", "b"),
password = c("a", "b"),
stringsAsFactors = FALSE
)
ui <- fluidPage(
verbatimTextOutput("auth_output")
)
ui <- secure_app(ui)
lang <- shinymanager:::language$new()
lang$add(
"Please authenticate" = "Test Page",
"Username:" = "Username:",
"Password:" = "Password:",
"Login" = "Sign in"
)
server <- function(input, output, session) {
users_data <- data.frame(START = Sys.time())
res_auth <- secure_server(
check_credentials = check_credentials(credentials)
)
output$auth_output <- renderPrint({
reactiveValuesToList(res_auth)
})
session$onSessionEnded(function() {
users_data$END <- Sys.time()
})
}
shinyApp(ui, server)
希望这有帮助