Skip to content

Instantly share code, notes, and snippets.

@jaehyeon-kim
Created April 14, 2016 23:15
Show Gist options
  • Save jaehyeon-kim/3dac30ba2be8b07531c986169db5f7aa to your computer and use it in GitHub Desktop.
Save jaehyeon-kim/3dac30ba2be8b07531c986169db5f7aa to your computer and use it in GitHub Desktop.
if(!require(shiny)) install.packages("shiny")
if(!require(shinythemes)) install.packages("shinythemes")
library(shiny)
library(shinythemes)
source("ui.R")
source("server.R")
shinyApp(ui, server)
is_logged <- FALSE;
auth_username <- 'username'
auth_password <- 'password'
server <- function(input, output, session) {
## check if user is logged in
auth <- reactiveValues(is_logged = is_logged)
observe({
if (auth$is_logged == FALSE) {
if (!is.null(input$login)) {
if (input$login > 0) {
username <- isolate(input$username)
password <- isolate(input$password)
is_same_username <- which(auth_username == username)
is_same_password <- which(auth_password == password)
if (length(is_same_username) > 0 & length(is_same_password) > 0) {
auth$is_logged <- TRUE
}
}
}
}
})
## render log-in or normal UI
observe({
if(!auth$is_logged) {
output$page <- renderUI({
div(class="outer", fluidPage(ui_login(), title = "Cadreon Dashboard - login", theme = shinytheme("cerulean")))
})
} else {
output$page <- renderUI({
div(class="outer", fluidPage(ui_main(), title = "Cadreon Dashboard - main", theme = shinytheme("cerulean")))
})
}
})
}
ui_login <- function() {
fluidRow(
tags$head(tags$style(HTML(".container-fluid {margin: 25px;}"))),
column(2, offset = 5,
div(id = "login_div",
wellPanel(
h4("LOGIN"),
textInput("username", "User name"),
passwordInput("password", "Password"),
br(),
actionButton("login", "Log in", icon = icon("user"))
)
)
)
)
}
ui_main <- function() {
fluidRow(
column(2, offset = 5,
wellPanel(h1("Hello!"))
)
)
}
ui <- (htmlOutput("page"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment