-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
292 lines (185 loc) · 7.53 KB
/
app.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# R packages
library(shiny)
library(shinythemes)
library(suncalc)
library(ggplot2)
library(maptools)
library(lubridate)
library(lutz)
library(tidygeocoder)
library(tibble)
library(dplyr, warn.conflicts = FALSE)
library(deSolve)
library(sf)
library(tidyverse)
library(scales)
library(plotly)
library(shinycssloaders)
library(waiter)
library(progress)
library(progressr)
#library(thematic)
#library(shinymaterial)
#times <- data.frame("Time" = c("Sunset", "Sunrise))
# Notes: UI to Server
# UI = User Interface
#theme = shinytheme("default")
# sunlight/sunset data = []
ui <- fluidPage(
# shinythemes::themeSelector(),
# theme = bslib::bs_theme(bootswatch = "darkly"),
actionButton("go", "go"),
textOutput("result"),
#withProgress({})
#waiter:use_waiter(),
navbarPage(
#theme = "darkly",
# OR
# theme = "superhero"
# OR
# theme = default
"School Light App",
tabPanel("Calculator",
sidebarPanel(
tags$h3("Enter Information:"),
# YYYY-MM-DD format for date
textInput("txt1", "Date:"),
textInput("txt2", "Location Information (Enter a valid address):"),
textOutput("text1")
# button to show graph or not maybe?
),
mainPanel(
h1("Sunrise and Sunset Calculator"),
h4("Sunrise and Sunset Times"),
verbatimTextOutput("txtout"),
# plotOutput("plot", click = "plot_click"),
actionButton("submitbutton", "Calculate"),
actionButton("clickedy", "What am I about to see?"),
plotOutput("plot")
) # mainPanel
), # Navbar 1, tabPanel
tabPanel("Attributions", "Arcascope @ https://arcascope.com",
textOutput("text0"),
imageOutput("photo"),
textOutput("text1"),
textOutput("text2")),
tabPanel("Important Data: Index vs Homeostat",
plotOutput("plot3"),
textOutput("text2")),
tabPanel("Important Data: Lights vs Times",
plotOutput("plot4"),
textOutput("text3")),
tabPanel("Settings (To be updated): ",
shinythemes::themeSelector(),
sliderInput("rating", "App Rating (0 being the worst and 20 being the best):",
min = 0, max = 20, value = 10)),
# Data Visualization: One bar represents sunrise
# and another bar represents sunset, each based on data from the
# input of the user
# CHANGE HISTOGRAM TO BAR GRAPH
# Note: Watch for commas and related errors
# 'Important Data: Timings' tab could have data
# ^ maybe?
) # navbarPage
) # fluidPage
# Define server function
server <- function(input, output, session) {
source(file.path("sample.r"), local = TRUE)$value
withProgress({
for (i in seq_len(10)) {
observeEvent(input$clickedy, {
showNotification("Good question - you'll get some sleep/wake times")
Sys.sleep(1)
showNotification("We'll then indicate your optimal time(s)")
Sys.sleep(1)
showNotification("In a few moments, you'll graphical output with that information")
})
#thematic::thematic_shiny()
#data <- eventReactive(input$go, {
#withProgress(message = "Loading. Please give us a second!", detail = 'This may take a while...', value = 0, session = getDefaultReactiveDomain(), {
output$plot3 <- renderPlot({
sample2(sunR, sunS)
})
output$photo <- renderImage({
list(
src = file.path("aphoto", paste0("yOIT88xWkbg", ".jpg")),
contentType = "image/jpeg",
width = 418,
height = 625
)
}, deleteFile = FALSE)
output$text0 <- renderText({
"Credits to the following papers for inspiring the research used in this application:"
})
output$text1 <- renderText({
"Phillips, Andrew J K, et al. “Modeling the Adenosine System as a Modulator of Cognitive Performance and Sleep
Patterns during Sleep Restriction and Recovery.” PLoS Computational Biology, U.S. National Library of Medicine,
26 Oct. 2017, https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5675465/. "
})
output$text2 <- renderText({
"Hannay, Kevin, et al. “Macroscopic Models for Human Circadian Rhythms - Sage Journals.” Sage Journals, 16 Oct.
2019, https://journals.sagepub.com/doi/10.1177/0748730419878298."
})
output$text1 <- renderText({
"Note: The x-axis is the Wake Times (AM) and the y-axis is the Average Sleep (Hours)"
})
output$text2 <- renderText({
"Graph of Index vs Homeostat"
})
output$text3 <- renderText({
"Graph of Lights vs Times"
})
output$plot4 <- renderPlot({
sample3(sunR, sunS)
})
output$txtout <- renderText({
# *ymd* func: can transform integers or numeric data into Date objects
# *strtoi* func: can convert strings to integers
# getSunlightTimes outputs things in dataframe type (basically a list/vector)
# CONVERT LAT AND LON INPUTS TO FLOATS/DECIMALS NOT INTEGERS
# *as.numeric* func: can convert strings into decimals or numeric types
someVar <- geo_cascade(input$txt2)
tb1 <- tibble(lat = 1:1)
str(someVar)
lat1 <- as.numeric(someVar$lat[1])
lon1 <- as.numeric(someVar$long[1])
sun <- getSunlightTimes(date = ymd(input$txt1),
keep = c("sunrise", "sunset"),
lat = lat1,
lon = lon1,
tz = tz_lookup_coords(lat1,
lon1, method="fast"))
sunR2 <- str(sun[1,4])
sunS2 <- str(sun[1,5])
if (input$submitbutton == 0)
return()
else
isolate(paste("Average sleep in hours: ", sep = " "))
#isolate(paste(sampleR(sunR, sunS)))
})
output$plot <- renderPlot({
avgsleepHours <- sampleR(sunR2, sunS2)
wakeAM <- c("10", "5", "6", "7", "8", "9")
ca.df <- data.frame(wakeAM, avgsleepHours)
if (input$submitbutton == 0)
return()
else
isolate(ggplot(ca.df, aes(x=wakeAM, y=avgsleepHours)) +
geom_bar(stat="identity", fill="lightblue") +
theme(
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
panel.background = element_blank(),
plot.background = element_blank())
)
# sampleR(sunR, sunS)
}, bg = "transparent")
incProgress(1 / length(10))
}
})
#})
# Note: Replace "sleep" with "sampleR" function when ready
# })
} # server
# Create Shiny object
shinyApp(ui = ui, server = server)