Advertisement
Guest User

Untitled

a guest
Feb 25th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. library(shiny)
  2. library(shinyauthr)
  3. library(shinyjs)
  4.  
  5. user_base <- data.frame(
  6. user = c("user1", "user2"),
  7. password = c("pass1", "pass2"),
  8. permissions = c("admin", "standard"),
  9. name = c("User One", "User Two"),
  10. stringsAsFactors = FALSE
  11. )
  12.  
  13. main_ui <- navbarPage("shinyauthr with Navbar Page",
  14. tabPanel("Plot",
  15. shinyauthr::logoutUI(id = "logout")
  16. ),
  17. tabPanel("Summary",
  18. verbatimTextOutput("summary")
  19. )
  20. )
  21.  
  22. ui <- tagList(shinyjs::useShinyjs(), uiOutput("ui"))
  23.  
  24. server <- function(input, output, session) {
  25.  
  26. # call the logout module with reactive trigger to hide/show
  27. logout_init <- callModule(shinyauthr::logout,
  28. id = "logout",
  29. active = reactive(credentials()$user_auth))
  30.  
  31. # call login module supplying data frame, user and password cols
  32. # and reactive trigger
  33. credentials <- callModule(shinyauthr::login,
  34. id = "login",
  35. data = user_base,
  36. user_col = user,
  37. pwd_col = password,
  38. log_out = reactive(logout_init()))
  39.  
  40. output$ui <- renderUI({
  41. if (credentials()$user_auth) {
  42. main_ui
  43. } else {
  44. fluidPage(shinyauthr::loginUI(id = "login"))
  45. }
  46. })
  47.  
  48. output$summary <- renderPrint({
  49. summary(cars)
  50. })
  51.  
  52. }
  53.  
  54. shinyApp(ui, server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement