Launch shinymanager authentification after click on button in the first tab then display other tabs

Viewed 119

I was wondering if it was possible to protect a shiny application with shinymanager but with having the possibility to access the first tab of the app before entering username and password while the second and third tab are hidden ?

I would like a "connect" button to launch the shinymanager page and then display the other tabs.

Does someone know if it is doable or should I use my own authentification form (which means less secured...) ?

My attempt:

library(shiny)
library(shinymanager)
library(shinydashboard)
library(shinyWidgets)
library(shinythemes)

credentials <- data.frame(
  user = c("user1"),
  password = c("1"),
  stringsAsFactors = FALSE
)

# user interface
ui <- navbarPage(id="navbarid",
                 "TEST",  theme = shinytheme("cosmo"),
                 header = tagList(
                   useShinydashboard()),

                 tabPanel(
                   "Welcome", fluidRow(align = "center", 
                        column(6, offset=4,
                               box(title = "Authentification", background = "black", 
                                 fluidRow(column(6, align = "center", style='padding-top:20px;',
                                    actionButton(inputId = "connect", label = "Log in")),
                                          column(6, align = "center", style='padding-top:20px;',
                                    actionButton(inputId = "register", label = "Register here"))))))),

                 tabPanel("Tab2", verbatimTextOutput("label1")
                   ),

                 tabPanel("Tab3", verbatimTextOutput("label2")
                 ))

ui <- secure_app(ui)

server <- function(input, output, session) {
  
  res_auth <- secure_server(
    check_credentials = check_credentials(credentials)
  )
  
  output$icon1 <- renderText(as.character(icon("sign-in-alt")))
  output$icon2 <- renderText(as.character(icon("users")))

  output$label1 <- renderText("First tab content here")
  output$label2 <- renderText("Second tab content here")
}

shinyApp(ui, server)

I tried to add

observeEvent(input$connect, {
  res_auth <- secure_server(
    check_credentials = check_credentials(credentials)
  )})

at the beginning of my server part but it didn't work !

0 Answers
Related