shinyauthr icon indicating copy to clipboard operation
shinyauthr copied to clipboard

Using shinyauthr with renderUser/dashboardUser

Open roman-tremmel opened this issue 4 years ago • 3 comments

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.

roman-tremmel avatar Dec 03 '19 15:12 roman-tremmel

can you post a reproducible example here please? thanks.

PaulC91 avatar Dec 03 '19 15:12 PaulC91

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)

roman-tremmel avatar Dec 03 '19 15:12 roman-tremmel

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

jjfantini avatar Mar 02 '22 17:03 jjfantini