PaulC91/shinyauthr

Using shinyauthr with renderUser/dashboardUser

Opened this issue · 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.

can you post a reproducible example here please? thanks.

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)

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