Last active
June 19, 2020 10:06
-
-
Save ofhouse/856b17c929f5a30efa0f7d3fc421d5e6 to your computer and use it in GitHub Desktop.
Simple password authentication for a shiny app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This is a Shiny web application. You can run the application by clicking | |
# the 'Run App' button above. | |
# | |
# Find out more about building applications with Shiny here: | |
# | |
# http://shiny.rstudio.com/ | |
# | |
library(shiny) | |
pok <- F | |
# Define UI for application that draws a histogram | |
ui <- fluidPage( | |
titlePanel("Shiny Password"), | |
sidebarLayout( | |
position = "left", | |
sidebarPanel(h3("sidebar panel"), | |
uiOutput("in.pss"), | |
uiOutput("in.clr")), | |
mainPanel(h3("main panel"), | |
plotOutput("distPlot")) | |
) | |
) | |
# Define server logic required to draw a histogram | |
server <- function(input, output) { | |
output$in.pss <- | |
renderUI({ | |
input$pss | |
if (pok) | |
return(NULL) | |
else | |
return(textInput("pss", "Password:", "")) | |
}) | |
output$in.clr <- | |
renderUI({ | |
input$pss | |
if (pok) | |
return(sliderInput( | |
"bins", | |
"Number of bins:", | |
min = 1, | |
max = 50, | |
value = 30 | |
)) | |
else | |
return(NULL) | |
}) | |
observe({ | |
if (!pok) { | |
password <- input$pss | |
if (!is.null(password) && password == "pass") { | |
pok <<- TRUE | |
} | |
} | |
}) | |
output$distPlot = renderPlot({ | |
input$pss | |
if (pok) { | |
# Check for NULL because input$bins is NULL on first rerender after the password input | |
if (is.null(input$bins)) { | |
return(NULL) | |
} | |
x <- faithful[, 2] | |
bins <- seq(min(x), max(x), length.out = input$bins + 1) | |
return(hist( | |
x, | |
breaks = bins, | |
col = 'darkgray', | |
border = 'white' | |
)) | |
} else { | |
return(NULL) | |
} | |
}) | |
} | |
# Run the application | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment