Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using shinyauthr with renderUser/dashboardUser #28

Open
roman-tremmel opened this issue Dec 3, 2019 · 3 comments
Open

Using shinyauthr with renderUser/dashboardUser #28

roman-tremmel opened this issue Dec 3, 2019 · 3 comments

Comments

@roman-tremmel
Copy link

roman-tremmel commented Dec 3, 2019

Is it possible to add the logout button in the User panel of the shinydashboardPlus' dashboardUser interface? When adding the button as it is, the button is not visible. Builing an own function without the hide function solves the problem, but then the login panel is not showing up after logout.

@PaulC91
Copy link
Owner

PaulC91 commented Dec 3, 2019

can you post a reproducible example here please? thanks.

@roman-tremmel
Copy link
Author

roman-tremmel commented Dec 3, 2019

of course.... (sorry the first version was really buggy. Now the app should demonstrate my problem)

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyauthr)
library(tidyverse)

user_base <- data_frame(
    user = c("user1", "user2"),
    password = sapply(c("pass1", "pass2"), sodium::password_store), 
    permissions = c("admin", "standard"),
    name = c("User One", "User Two")
)

header <- dashboardHeaderPlus(userOutput("SUPER_USER"),
                              # you can add the button here.... but I want the button in the user dashboard see below. 
                              # in addition after log out the modal is showing, but without the log in fields. 
                              tags$li(class = "dropdown", style = "padding: 8px;",
                                      shinyauthr::logoutUI("logout"))
                              )
sidebar <- dashboardSidebar()
body = dashboardBody(shinyjs::useShinyjs())
ui <- dashboardPagePlus(header, sidebar, body)

server <- function(input, output, session) {

    start_up_modal <- function(){
        modalDialog(
            easyClose = F,
            shinyauthr::loginUI(id = "login"),
            footer = NULL)
    }
    showModal(start_up_modal())

    logout_init <- callModule(shinyauthr::logout, 
                              id = "logout", 
                              active = reactive(credentials()$user_auth))
    
    credentials <- callModule(shinyauthr::login, 
                              id = "login", 
                              data = user_base,
                              user_col = user,
                              pwd_col = password,
                              sodium_hashed = T,
                              log_out = reactive(logout_init()))
    observe({
        if(credentials()$user_auth){
        removeModal()}else{
        showModal(start_up_modal())
        }
    })

    output$SUPER_USER <- renderUser({
        req(credentials()$user_auth)
        dashboardUser(
            name = credentials()$info$name,
            subtitle =  credentials()$info$permissions, 
            src =  "https://adminlte.io/themes/AdminLTE/dist/img/user2-160x160.jpg", 
            footer = 
                actionButton("btn", "this shows up"),
                # here it is not rendered:
                shinyauthr::logoutUI("logout")
                )
        })
}
shinyApp(ui = ui, server = server)

@jjfantini
Copy link

How did you go about utilizing actionButton() in the server? @PaulC91 @roman-tremmel @olreim @ChuckHend @laresbernardo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants