首页 > 解决方案 > 如何使用 shinymanager 包为不同的登录创建不同的应用程序?R闪亮

问题描述

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();"

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),
  
# classic ui logic

server <- function(input, output, session) {
  
  # call the server part
  # check_credentials returns a function to authenticate users
  res_auth <- secure_server(
    check_credentials = check_credentials(credentials)
  )
  
  output$auth_output <- renderPrint({
    reactiveValuesToList(res_auth)
  })
  
  # classic server logic
}
shinyApp(ui, server)

有没有办法用 shinymanager 包识别不同的用户?像这样的东西:

if(user=="fanny"){
#one dashboard
}
if(user=="benoit"){
#another dashboard
}

我的意图是根据谁登录创建不同的应用程序......如果用户是 Benny,如果是 Benoit,则显示一个应用程序,如果是 Victor,则显示另一个应用程序。

标签: rshiny

解决方案


另一个线程中提供了类似的答案。解决方案是将凭证放入反应值中。您可以使用 creds_reactive()$user 访问当前登录的用户并定义自定义应用程序


推荐阅读