How to create a login page in shiny?
Here is my solution. It is not perfect but it is simple.
library(shiny)
ui <- fluidPage(
conditionalPanel(
condition = "input.password != 'password'",
textInput("password", "Password:", value = "Type the password here")
),
conditionalPanel(
condition = "input.password == 'password'",
fluidRow(
column(2,
textInput("Green", "Green:", value = "24716"),
textInput("Blue", "Blue:", value = "24700")
)
)
),
plotOutput(outputId = "distPlot")
)
server <- function(input, output, session) {
output$distPlot <- renderPlot({
if (input$password!="password") return(0)
plot(c(1,2,3),c(1,2,3))
})
}
app=shinyApp(ui, server)
I think you have two issues here:
First your confirm button value is stored here: input$"ui1Output-confirm"
and not here: input$confirm
I would suggest to replace:
observeEvent(is.null(input$confirm), {
Logged <<- F
})
By:
observeEvent(input$"ui1Output-confirm", {
Logged <<- T
})
Then your observe function does not contain any reference to the button so it is not executed when the user clicks on it. I don't have a proper solution for this but a simple hack would be to add:
tmp <- input$"ui1Output-confirm"
at the begining of the observe section:
observe({
tmp <- input$"ui1Output-confirm"
if (Logged == FALSE) {
output$page <- renderUI({
ui1Output('ui1Output')
})
output$lsuId <- renderText({ input$lsuId })
}
if (Logged == TRUE)
{
output$page <- renderUI({ ui2 })
}
})