Here is a very primitive version of displaying different data depending on the user name and password entered. I used the bcrypt package to generate hashed passwords and to check the password validity. In a real version, I would probably use conditionalPanel() to show the plot, rather than what I did here. I hope it gives you an idea of how to proceed.
library(bcrypt)
library(shiny)
library(tibble)
#In the real app, prepare passwords beforehand and store them in a file or data base
PasswordDF <- data.frame(username = c("alpha", "beta", "gamma"),
HashedPassword = c(hashpw("artichoke"), hashpw("crabapple"), hashpw("eggplant")),
group = c("A", "B", "C"),
stringsAsFactors = FALSE
)
Dat <- tibble(group = c(rep("A", 3), rep("B", 3), rep("C", 3)),
x = rep(1:3, 3),
y = c(2,3,4,14,13,12,23,22,24))
ui <- fluidPage(
titlePanel("Mock App"),
fluidRow(
column(width = 2,
textInput("user", "User Name")
),
column(width = 2,
passwordInput("PW", "Password")
),
column(width = 2,
actionButton("button", "Log in")
)
),
fluidRow(
plotOutput("plot")
)
)
server <- function(input, output) {
filteredDat <- eventReactive(input$button, {
if (input$user %in% PasswordDF$username &&
checkpw(input$PW,
hash = PasswordDF[PasswordDF$username == input$user, "HashedPassword"])) {
Dat %>% filter(group == PasswordDF[PasswordDF$username == input$user, "group"])
} else data.frame(x = 0, y = 0)
})
output$plot <- renderPlot({ plot(filteredDat()$x, filteredDat()$y, main = isolate(input$user), type = "b") })
}
# Run the application
shinyApp(ui = ui, server = server)```