Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- library(shinyauthr)
- library(shinyjs)
- user_base <- data.frame(
- user = c("user1", "user2"),
- password = c("pass1", "pass2"),
- permissions = c("admin", "standard"),
- name = c("User One", "User Two"),
- stringsAsFactors = FALSE
- )
- main_ui <- navbarPage("shinyauthr with Navbar Page",
- tabPanel("Plot",
- shinyauthr::logoutUI(id = "logout")
- ),
- tabPanel("Summary",
- verbatimTextOutput("summary")
- )
- )
- ui <- tagList(shinyjs::useShinyjs(), uiOutput("ui"))
- server <- function(input, output, session) {
- # call the logout module with reactive trigger to hide/show
- logout_init <- callModule(shinyauthr::logout,
- id = "logout",
- active = reactive(credentials()$user_auth))
- # call login module supplying data frame, user and password cols
- # and reactive trigger
- credentials <- callModule(shinyauthr::login,
- id = "login",
- data = user_base,
- user_col = user,
- pwd_col = password,
- log_out = reactive(logout_init()))
- output$ui <- renderUI({
- if (credentials()$user_auth) {
- main_ui
- } else {
- fluidPage(shinyauthr::loginUI(id = "login"))
- }
- })
- output$summary <- renderPrint({
- summary(cars)
- })
- }
- shinyApp(ui, server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement