-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.R
208 lines (194 loc) · 8 KB
/
ui.R
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
library(shiny)
# Define UI for the dashboard.
shinyUI(fluidPage(
# JavaScript to submit forms on ENTER (specific to these input ids).
# Add CSS to change the font color of the login and sign up error messages, and sign up's display message.
tags$head(
tags$script(src = "formSubmit.js"),
tags$style("#loginErrorMessage { color: red; }"),
tags$style("#signupErrorMessage { color: red; }"),
tags$style("#signupDisplayMessage { color: #428bca; }"),
tags$style("#healthyText { text-align: center; margin-top: 12px; }"),
tags$style("#advertiseText { text-align: center; margin-top: 12px; }")
),
# Application title
titlePanel("Cafe Data Predictor"),
# Output the user's login status as a div (used with conditionalPanels)
textOutput("loggedIn"),
# Hide the div created above.
# Note: display: 'none' cannot be used as the javascript expressions used by the conditionalPanels below will not be able to read
# the value for loggedIn.
tags$script("
$('#loggedIn').css('height', '0');
$('#loggedIn').css('overflow', 'hidden');
"),
# Displays that the user is logged in and their username.
textOutput("loginStatus"),
# This panel is only displayed if the user is not logged in (Login screen)
conditionalPanel(condition = "output.loggedIn == '0'", # This condition parameter requires a javascript expression.
tabsetPanel(
# Login page
tabPanel("Login",
mainPanel(
# Username and password input with a submit button
textInput("loginUsername", "Username:"),
br(),
passwordInput("loginPassword", "Password:"),
actionButton("loginButton", "Submit"),
br(), br(),
# Used to display if the user's credintials were incorrect.
textOutput("loginErrorMessage")
)
),
# Sign up page
tabPanel("Sign Up",
mainPanel(
textInput("signupUsername", "Username:"),
br(),
passwordInput("signupPassword1", "Password:"),
br(),
passwordInput("signupPassword2", "Re-enter password:"),
#br(),
actionButton("signupButton", "Sign Up"),
br(), br(),
htmlOutput("signupErrorMessage"),
htmlOutput("signupDisplayMessage")
)
)
)
),
# This panel is only displayed if the user is logged in (Predictors)
conditionalPanel(condition = "output.loggedIn == '1'",
actionLink("logoutButton", "Logout"),
tags$script("
$('#logoutButton').css('float', 'right');
$('#logoutButton').css('display', 'in-line');
"),
# Create a panel to contain the tabs for each predictor.
tabsetPanel(
# Customer predictor: user enters values on the current time and weather and a plot is created containing
# the predicted amount of customers.
tabPanel("Customer Predictor",
# Sidebar inputs used to predict the amount of customers at a given time.
sidebarLayout(
sidebarPanel(
# DayOfWeek input (drop down)
selectInput("dayOfWeek", "Day of the week:",
c("Monday" = "MONDAY",
"Tuesday" = "TUESDAY",
"Wednesday" = "WEDNESDAY",
"Thursday" = "THURSDAY",
"Friday" = "FRIDAY",
"Saturday" = "SATURDAY",
"Sunday" = "SUNDAY")),
br(),
# Temperature input (numeric text box)
numericInput("temp", "Temperature (F):",
value = 0),
br(),
# Precipitation input (drop down)
selectInput("prec", "Precipitation:",
c("Clear" = "Clear",
"Cloudy" = "Clouds",
"Drizzling" = "Drizzle",
"Fog" = "Fog",
"Misty" = "Mist",
"Raining" = "Rain",
"Snowing" = "Snow")),
br(),
# Time input (double-ended datetime slider)
# Uses only the time part of R's datetime object POSIXlt in the UTC timezone so that the user's timezone
# does not affect the values. Steps the slider for every 5 minutes of time.
sliderInput("time",
"Time",
min = strptime("00:00", "%H:%M", tz = "UTC"),
max = strptime("23:59", "%H:%M", tz = "UTC"),
value = c(strptime("11:00", "%H:%M", tz = "UTC"), strptime("13:00", "%H:%M", tz = "UTC")),
step = 60*5,
timeFormat = "%H:%M",
timezone = "+0000") # UTC
),
# Create a panel to display both the plot and text outputs defined in the server logic.
mainPanel(
plotOutput("plot", width = "100%"),
textOutput("text")
)
)
),
# Healthy predictor: user enters values on a customer to see the probability that they will buy a healthy item.
tabPanel("Healthy Predictor",
sidebarLayout(
sidebarPanel(
# DayOfWeek input (drop down)
selectInput("healthyDayOfWeek", "Day of the week:",
c("Monday" = "Monday",
"Tuesday" = "Tuesday",
"Wednesday" = "Wednesday",
"Thursday" = "Thursday",
"Friday" = "Friday")),
br(),
# Hour input (numeric slider)
sliderInput("healthyHour","Hour of day:",
value = 12,
min = 0, max = 23),
br(),
# Gender input (drop down)
selectInput("healthyGender","Gender:",
c("Female" = "Female",
"Male" = "Male")),
br(),
# Age input (drop down)
selectInput("healthyAge","Age:",
c("Adult" = "Adult",
"Child" = "Child",
"Senior" = "Senior",
"Young Adult" = "Young Adult")),
br(),
# Advertised Item's Health input (drop down)
selectInput("healthyAdvHealth","Advertised Item's Healthiness:",
c("Healthy" = "Healthy",
"Unhealthy" = "Unhealthy")),
br(),
# Advertised Item's Temperature input (drop down)
selectInput("healthyAdvTemp","Advertised Item's Temperature:",
c("Cold" = "Cold",
"Hot" = "Hot")),
br(),
# Precipitation input (drop down)
selectInput("healthyPrecipitation", "Precipitation outside:",
c("Clear" = "Clear",
"Cloudy" = "Clouds",
"Drizzling" = "Drizzle",
"Fog" = "Fog",
"Misty" = "Mist",
"Raining" = "Rain",
"Snowing" = "Snow"))
),
# Create a panel to display the output of the predictor
mainPanel(
htmlOutput("healthyText")
)
)
),
tabPanel("Advertisement Predictor",
sidebarLayout(
sidebarPanel(
#Advertised Item Temperature input (drop down)
selectInput("advProdTemp", "Advertised Item Temperature:",
c("Hot" = "Hot",
"Cold" = "Cold")),
br(),
#Advertised Item Health input (drop down)
selectInput("advProdHealth", "Advertised Item Health:",
c("Healthy" = "Healty",
"Unhealthy" = "Unhealthy"))
),
# Main Panel Displays Output of Prediction
mainPanel(
htmlOutput("advertiseText")
)
)
)
)
)
))