How to hide the content before entering the password and add Footer to the shiny

Viewed 206

So I am building this shiny app on shinydashboard, which has a password-authenticator, however, the sidebar and the content are not hidden and can be accessed despite having the password-authenticator. How can I make it so that everything is hidden, prior entering the password, so every menuItem, menusubItem, etc are hidden? What would be the solution here?

Also, I would like to add a footer at the bottom of the page, something like:

footer  = div(hr(style = 'color:grey;width:50%'),
                               p('Property of Disneyland', 
                             style = 'color:grey;font-size:11px;text-align:center'))

Grateful for all your help

library("easypackages")
packages("ggplot2","shinyauthr","shinyBS", "plyr","shinyjs" ,"dplyr" , "tidyverse","tidyquant","readxl", "shiny","shinydashboard","ISLR","MASS","DT","inspectdf","DataExplorer")
options(shiny.maxRequestSize = 30*1024^2)



# sample logins dataframe with passwords hashed by sodium package
user_base <- tibble(
  user = c("Jack", "Eric", "Marcus", "Barack"),
  password = sapply(c("12345", "12345", "12345", "12345"), sodium::password_store), 
  permissions = c("admin", "standard", "standard", "standard"),
  name = c("User One", "User Two","User Three", "User Four")
)




ui <-shinyUI( 
  dashboardPage(skin = "blue",
                dashboardHeader( 
                  title = "Model",titleWidth = 400,
                  tags$li(class = "dropdown", style = "padding: 8px;",shinyauthr::logoutUI("logout"))),
                
                                 
                dashboardSidebar(
                  
                  collapsed = TRUE, sidebarMenuOutput("sidebar"),
                  sidebarMenu(
                    id = "tabs",
                    menuItem('Load and View Data',tabName = 'data',icon = icon('save')),
                    menuItem('Visualizing data',tabName = 'visual',icon = icon('chalkboard-teacher')),
                    menuItem("Under Development",tabName = "info", icon = icon("info")),
                    menuItem("Model selection", tabName = "main_model", icon = icon("folder"),startExpanded=T,
                             menuSubItem('models',
                                         tabName = 'model',selected=T),
                             menuSubItem("PP",tabName = "model",selected =T),
                             menuSubItem("PD",tabName = "model",selected = T,icon =icon("book-medical")),
                             menuSubItem("DD",tabName = "model",selected = T,icon =icon("capsules")),
                             menuSubItem("DD",tabName = "model",selected = T,icon =icon("biohazard")),
                             menuSubItem("DD",tabName = "model",selected = T,icon =icon("briefcase-medical")),
                             menuSubItem("DD",tabName = "model",selected = T,icon =icon("brain"))
                             
                             
                    ),
                    
                    
                    
                    
                    
                    menuItem("Simulation details", tabName = "siminfo", icon = icon("file-invoice"),startExpanded =T,
                             menuSubItem("PD",tabName = "model",selected = T,icon =icon("book-medical")),
                             menuSubItem("PD",tabName = "model",selected = T,icon =icon("book-medical")),
                             menuSubItem("PD",tabName = "model",selected = T,icon =icon("book-medical")),
                             menuSubItem("PD",tabName = "model",selected = T,icon =icon("book-medical")),
                             menuSubItem("PD",tabName = "model",selected = T,icon =icon("book-medical"))),
                    
                    
                    menuItem("Simulation output", tabName = "output", icon = icon("chart-area")),
                    actionButton("do", "Start simulation",icon = icon("paper-plane"),style='background-color: #FF9933; ' ),
                    hr()
                    
                  )
                ),
                
                ####body of the app####
                dashboardBody(
                  shinyjs::useShinyjs(),
                  
                  shinyauthr::loginUI("login"),
                  
                  tabItems(
                    tabItem(
                      tabName = 'data',
                      fileInput("data", "Load Data(CSV Only for now!)",
                                multiple = FALSE,
                                accept = c("text/csv",
                                           "text/comma-separated-values,text/plain",
                                           ".csv")),
                      DT::dataTableOutput('dt'),
                      h3('Data Type Converter'),
                      uiOutput('colname'),
                      selectInput('coltype','Change type to :',choices = c('Categorical','Numerical')),
                      actionButton('convert','Convert')
                    ),
                    
                    tabItem(
                      tabName = 'visual',
                      uiOutput('draw_colname'),
                      actionButton('draw','Draw Plot'),
                      plotOutput('plot_selected')
                      
                    ),
                    
                    tabItem("tab1", uiOutput("tab1_ui")),
                    tabItem("tab2", uiOutput("tab2_ui")),
                    tabItem(tabName = "model"),
                    tabItem(tabName = "siminfo"),
                    tabItem(tabName = "output")

                  )
                )
  ))




server <- function(input, output, session) {
  
  # login status and info will be managed by shinyauthr module and stores here
  credentials <- callModule(shinyauthr::login, "login", 
                            data = user_base,
                            user_col = user,
                            pwd_col = password,
                            sodium_hashed = TRUE,
                            log_out = reactive(logout_init()))
  
  # logout status managed by shinyauthr module and stored here
  logout_init <- callModule(shinyauthr::logout, "logout", reactive(credentials()$user_auth))
  
  # this opens or closes the sidebar on login/logout
  observe({
    if(credentials()$user_auth) {
      shinyjs::removeClass(selector = "body", class = "sidebar-collapse")
    } else {
      shinyjs::addClass(selector = "body", class = "sidebar-collapse")
    }
  })
  
  # only when credentials()$user_auth is TRUE, render your desired sidebar menu
  output$sidebar <- renderMenu({
    req(credentials()$user_auth)
    sidebarMenu(
      id = "tabs",
      menuItem("Storms Data", tabName = "tab1"),
      menuItem("Starwars Data", tabName = "tab2")
    )
  })
  
  # tab 1 UI and output ----------------------------------------
  output$tab1_ui <- renderUI({
    req(credentials()$user_auth)
    DT::DTOutput("table1")
  })
  
  output$table1 <- DT::renderDT({
    DT::datatable(dplyr::storms, options = list(scrollX = TRUE))
  })
  
  
  
  
  # tab 2 UI and output ----------------------------------------
  output$tab2_ui <- renderUI({
    req(credentials()$user_auth)
    DT::DTOutput("table2")
  })
  
  output$table2 <- DT::renderDT({
    DT::datatable(dplyr::starwars[,1:10], options = list(scrollX = TRUE))
  })
  
  
  
  df = reactive(data.table::fread(input$data$datapath))
  
  #Render Dataframe 
  output$dt = DT::renderDataTable({
    req(input$data)
    df()
  })
  
  #Colnames for data type converter
  output$colname = renderUI({
    req(input$data)
    selectInput('colname','Variable Name',choices = colnames(df()))
  })
  
  #Colnames for draw data
  output$draw_colname = renderUI({
    req(input$data)
    selectInput('draw_colname','Variable Name',choices = colnames(df()),multiple = T)
  })
  
  #Select variables from data and make plot
  observeEvent(input$draw,{
    req(input$data)
    output$plot_selected = renderPlot({
      select(df(),input$draw_colname) %>% plot})
  })
  
  output$summary = renderPrint({
    dataset <- get(input$dataset, "package:datasets", inherits = FALSE)
    summary(dataset)
  })
  
  output$table = renderTable({
    dataset <- get(input$dataset, "package:datasets", inherits = FALSE)
    dataset
  })
  
  output$glimpse = renderPrint({
    dataset <- get(input$dataset, "package:datasets", inherits = FALSE)
    glimpse(dataset)
  })
  
  output$inspectdf_types = renderPlot({
    dataset <- get(input$dataset, "package:datasets", inherits = FALSE)
    inspect_cat2(as.data.frame(dataset)) %>% show_plot()
  })
  
}


shiny::shinyApp(ui, server)  
0 Answers
Related