Last active
April 24, 2023 18:47
-
-
Save PaulC91/2a1b9ba57a53869ba82093720a9a8fa0 to your computer and use it in GitHub Desktop.
Example of how to use shinyauthr with a shiny navbarPage UI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
) | |
ui <- tagList( | |
shinyjs::useShinyjs(), | |
tags$head(includeScript("logout-button.js")), | |
navbarPage( | |
id = "tabs", | |
title = "shinyauthr with Navbar Page", | |
tabPanel("Home", loginUI("login"), uiOutput("homepage")), | |
tabPanel("Data", tableOutput("tbl")) | |
) | |
) | |
server <- function(input, output, session) { | |
# go back to the home tab after logout | |
observeEvent(credentials()$user_auth, { | |
updateNavbarPage(session, "tabs", selected = "Home") | |
}) | |
# call the logout module with reactive trigger to hide/show | |
logout_init <- callModule(logout, | |
id = "logout", | |
active = reactive(credentials()$user_auth)) | |
# call login module supplying data frame, user and password cols | |
# and reactive trigger | |
credentials <- callModule(login, | |
id = "login", | |
data = user_base, | |
user_col = user, | |
pwd_col = password, | |
log_out = reactive(logout_init())) | |
output$homepage <- renderUI({ | |
req(credentials()$user_auth) | |
tags$h1("Something in the homepage") | |
}) | |
output$tbl <- renderTable({ | |
req(credentials()$user_auth) | |
credentials()$info | |
}) | |
} | |
shinyApp(ui, server) |
Good day Paul, i have managed to find your solution for this you posted on the R Studio Community. Once again, thank you very much for your valued contribution
glad to hear you found the solution you needed!
If anyone wants to know where the answer to the question is, it's here: https://community.rstudio.com/t/shinyauthr-with-shinydashboard-layout/30501/4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Paul
Can one use Shinyauthr with a shiny dashboard and do you have use cases of this?
My dashboard looks like this:

My code is as follows: