Search code examples
rshinyshiny-server

Can't get the information for the current user


As you can see in the following code, after successfully logging in, it should print the user information containing the user, admin comment, and the start/expiring date from the credentials data-frame, on the first page. However, it does not show up. What could be the problem? grateful for guidance.

# define some credentials
credentials <- data.frame(
  user = c("11", "1", "1", "1"), # mandatory
  password = c("1", "1", "1", "1"), # mandatory
  start = c("2022-02-14"), # optinal (all others)
  expire = c(NA, "2019-12-31"),
  admin = c(TRUE, TRUE, FALSE, FALSE),
  comment = "Welcom to the Shiny applications.",
  stringsAsFactors = FALSE
)

library(shiny)
library(shinymanager)

ui<-fluidPage(
  navbarPage(
  "Shiny",
  tabPanel(
    "Information"),
  tags$h2("Information about the current user"),
  verbatimTextOutput("auth_output")
  
  
  
  )
)



# Wrap your UI with secure_app
ui <- secure_app(ui)


server <- function(input, output, session) {
  
  # call the server part
  # check_credentials returns a function to authenticate users
  res_auth <- secure_server(
    check_credentials = check_credentials(credentials)
  )
  
  output$auth_output <- renderPrint({
    reactiveValuesToList(res_auth)
  })
  
  # your classic server logic
  
}

shinyApp(ui, server)

Solution

  • You need a panel such as mainPanel in your navbarPage:

    ui<-fluidPage(
      navbarPage(
        "Shiny",
        tabPanel(
          "Information"),
        tags$h2("Information about the current user"),
        mainPanel(
          verbatimTextOutput("auth_output")
        )
      )
    )
    

    enter image description here