How create different apps for different logins with shinymanager package? R Shiny

Viewed 174
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)

There is a way to identify different users with shinymanager package? Something like this:

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

My intention is to create different apps depending on who is logged in... if the user is Benny, show one app if it's Benoit, show another, if it's Victor, show another.

1 Answers

There was a similar answer provided in another thread. Solution is to put credentials into reactive values. You could use the creds_reactive()$user to access which user is currently logged in and define a custom app

Related