-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.R
More file actions
99 lines (84 loc) · 2.58 KB
/
app.R
File metadata and controls
99 lines (84 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
##################################
# Created by Epi-interactive
# 18 May 2019
# https://www.epi-interactive.com
##################################
library(shiny)
library(bcrypt)
# Define UI for application that draws a histogram
ui <- fluidPage(
tags$head(
tags$link(rel = "stylesheet", type = "text/css", href = "css/style.css")
),
uiOutput("mainUI")
)
# Define server logic required to draw a histogram
server <- function(input, output) {
# The expected username and password are admin/admin
# The long password string in the following variable is generated by hashpw("admin")
credentials <- reactiveValues(userIsAuth = FALSE, username = "admin",
password = "$2a$12$jxoOXWVRB0XPJzfyViVjY.NkgqZlCcW4UbnOjRPvppH0ENRlH8s3y")
observeEvent(input$loginbtn, {
if(input$username == credentials$username)
{
credentials$userIsAuth <- checkpw(input$password, credentials$password)
}
else
{
showModal(modalDialog(
title = "Error",
"Incorrect username or password. please try again! (Hint: admin/admin)"
))
}
})
output$mainUI <- renderUI({
if(credentials$userIsAuth){
tagList(
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
uiOutput("sliderInput"),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
}else{
#Display the login screen
div(class="login-wrapper",
div(class="login",
h1("User Authentication"),
hr(),
textInput("username", "Username:"),
passwordInput("password", "Password:"),
fluidRow(
actionButton("loginbtn", "Login", class = "btn-primary full-width")
),
fluidRow(
tags$img(src="images/Epi_Logo.png", width= "300px")
)
)
)
}
})
output$sliderInput <- renderUI({
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
)
})
output$distPlot <- renderPlot({
req(input$bins)
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)