Password protect(ish) your Shiny app

Ihate-Passwords-2

I have trawled through various blogs looking for ways in which to password protect my Shiny apps. As a self described ‘coding moron’, I have struggled with some of the more complicated suggestions. So I set out to find the simplest, cleanest solution to my password protection woes, and here it is:

Disclaimer: This is not designed to give you high level password protection. Anyone with advanced computer skills can easily circumnavigate this protection and view your app/data.

library(shiny)

ui <- fluidPage(

  # Application title
  titlePanel("My password protected Shiny App"),

  # Sidebar with user input elements
  sidebarLayout(
    sidebarPanel(
      passwordInput("pwIn", "Passcode")

    ),

    # Show a plot
    mainPanel(
      plotOutput("distPlot")
    )
  )
)

server <- function(input, output) {

  output$distPlot <- renderPlot({

    #This is essentially your password code snippet. The below graoh will not run
    #unless you type the password; test
    validate(
      need(input$pwIn=="test", "Please enter the passcode"
      ))

    #Generate data and draw plot
    x<-sample(1:10,10)
    y<-sample(1:10,10)
    plot(x,y)

  })
}

#Run the application
shinyApp(ui = ui, server = server)