forked from CHRL-VIU/chrl-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
289 lines (243 loc) · 12.2 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
library(dplyr)
library(DBI)
library(plotly)
library(lubridate)
library(leaflet)
library(tsibble)
library(shinyWidgets)
library(shinydashboard)
library(dashboardthemes)
library(weatherdash)
Sys.setenv(TZ = 'UTC')
# set colorblind safe color pallet
# http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/#a-colorblind-friendly-palette
cbs_pal <-
c(
"#000000",
"#E69F00",
"#009E73",
"#F0E442",
"#CC79A7",
"#56B4E9"
)
# grab login creds
source("config.r")
# set list of stns with tipping bucket problems
list_stn_tipping_bucket_errs <- 'mountarrowsmith'
# set the down stations to show a popup model for
down_stations <- NA
# Station Coords
stnCoords <- read.csv("stnloc.csv")
# set initial staiton
cur_stn = "apelake"
# add message to display at top of graph pages
siteNoticeMsg <- "Note: To automatically load your favourite station when you visit our site, select a station from the 'Choose a Weather Station' dropdown and then bookmark the link in the address bar. <br/>"
tetrahedronDisclaimer <- "The tipping bucket is currently malfunctioning at this station and total precipitation (stand pipe) is shown instead."
# load graphing presets
source('R/graph-presets.R')
# load logo paths, parameter dictionary, stn name dictionary
source('R/dictionaries.R')
# Station Meta List - this is a nested list
source('R/station-meta-list.R')
#### user interface ####
ui <- function(request) {
dashboardPage(title = "CHRL Real-time Weather",
dashboardHeader(title = tags$a(href='http://www.viu-hydromet-wx.ca/',
tags$img(src="logo_update.png",
style="padding-right:10px;padding-bottom:10px",
height = 60), target="_blank")
),
dashboardSidebar(
collapsed = F,
uiOutput("sidebarControls"),
sidebarMenu(id = "smenu",
menuItem("Current Conditions", tabName = "map", icon = icon("fas fa-map")),
menuItem("Weekly Summary", tabName = "wkly_graph", icon = icon("fas fa-chart-line")),
menuItem("Custom Graphs", tabName = "cstm_graph", icon = icon("fas fa-chart-line")),
menuItem("Annual Comparisons", tabName = "ann_compare", icon = icon("fas fa-chart-line")),
menuItem("Station Comparisons", tabName = "stn_compare", icon = icon("fas fa-chart-line")),
menuItem("Webcams", icon = icon("fas fa-camera"), href = "https://viu-hydromet-wx.ca/webcam-viewer/")
)
),
dashboardBody(
# add dashboard styling
customTheme,
# add styling for graph formating
tags$head(
tags$link(rel = "stylesheet", type = "text/css", href = "viu.css")
),
tabItems(
tabItem("map",
div(class="outer",
tags$head(
# Include our custom CSS
includeCSS("www/mapstyles.css")
),
leafletOutput("map", width="100%", height="100%")
)
),
tabItem("wkly_graph",
fluidRow(
column(12,
h1("Weekly Summary", align = "center")
)
),
fluidRow(
column(width = 3,
# tags$head(
# tags$style(type="text/css", ".well { min-width: 320px; }")
# ),
selectInput("preset_site",
label = "Choose a Weather Station:",
choices = stnNameDict,
selected = cur_stn,
selectize = F),
tableOutput("precipTable"),
hr(style = "border-top: 1px solid #bfbfbf;"),
htmlOutput('partnerLogoUI'),
h5(".", align = "center", style = "color:whitesmoke") # blank row so images dont span below sidebar panel.
),
column(width = 9,
htmlOutput('header'),
wellPanel(class ="line_graph_container",
plotlyOutput("plot_T_RH", height = "40vh")),
wellPanel(class ="line_graph_container",
plotlyOutput("plot_Snow", height = "40vh"),
radioButtons("cleanSnow", "Preform automated spike correction on Snow Depth?:", inline = T,
c("Yes" = "yes",
"No" = "no"))),
uiOutput("windplots")
)
)
),
tabItem("cstm_graph",
fluidRow(
column(12,
h1("Custom Graphs", align = "center")
)
),
fluidRow(
column(2,
selectInput("custom_site",
label = "Choose a Weather Station:",
choices = stnNameDict,
selected = cur_stn,
selectize = F
),
selectInput("custom_year", "Select Water Year", "", selectize = F),
uiOutput("varSelection"),
uiOutput("cleanSnowButton")
),
column(10,
htmlOutput('header2'),
wellPanel(
plotlyOutput("plot1", height = "40vh"),
chooseSliderSkin('Flat',color = "#99ccff"),
div(style = "margin-top:-3.5em; margin-bottom: -2em",
fluidRow(uiOutput("slider"), align = 'center'))
),
htmlOutput('partnerLogoUI_custom')
)
)
),
tabItem("ann_compare",
fluidRow(
column(12,
h1("Annual Comparison", align = "center")
)
),
fluidRow(
column(2,
selectInput("annual_site",
label = "Choose a Weather Station:",
choices = stnNameDict,
selected = cur_stn,
multiple = F,
selectize = F
),
uiOutput("varSelection_ann"),
selectInput("compare_year", "Select Years to Compare: ", "", multiple = T)
),
column(10,
htmlOutput('header3'),
wellPanel(
plotlyOutput("plot2", height = "40vh"),
),
htmlOutput('partnerLogoUI_annCompare')
)
)
),
tabItem("stn_compare",
fluidRow(
column(12,
h1("Station Comparison", align = "center")
)
),
fluidRow(
column(2,
selectInput("station_site",
label = "Choose a Weather Station:",
choices = stnNameDict,
selected = c('homathko', 'klinaklini'),
multiple = T,
selectize = T
),
uiOutput("varSelection_stn"),
selectInput("station_year", "Select Year to Compare: ", "")
),
column(10,
htmlOutput('header_compare_stn'),
wellPanel(
plotlyOutput("plot_compare_stn", height = "40vh"),
)
)
)
)
)
)
)
}
#### server ####
server <- function(input, output, session) {
##### create disclaimer dialog box and declare it open on start up #####
# initial state for modal so its only shown once
modalShown <- FALSE
observe({
if(input$smenu == "map" & modalShown == FALSE){
if(!modalShown){
showModal(disclaimer_EN)
modalShown <<- TRUE # need to use super asigner to affect global var
}
}
})
observeEvent(input$ack, {
removeModal()
})
observeEvent(input$FN, {
removeModal()
showModal(disclaimer_FR)
})
observeEvent(input$EN, {
showModal(disclaimer_EN)
})
#### source rest of app ####
source("classes/map.r", local = TRUE)
source("classes/modal.r", local = TRUE)
source("classes/presets.r", local = TRUE)
source("classes/custom.r", local = TRUE)
source("classes/annual.r", local = TRUE)
source("classes/station_compare.r", local = TRUE)
# enable bookmarking on URL
observe({
# Trigger this observer every time an input changes
reactiveValuesToList(input)
session$doBookmark()
})
onBookmarked(function(url) {
updateQueryString(url)
})
# inputs to exclude from URL
setBookmarkExclude(c("map_click", "cleanSnow", "cleanSnowCstm","plotly_hover-A", "annual_site", "sidebarItemExpanded", "plotly_hover", "map_bounds", "map_center", "map_zoom", "map_groups",".clientValue-default-plotlyCrosstalkOpts", "plotly_afterplot-A", "sliderTimeRange", "map_marker_mouseout", "map_marker_mouseover","map_marker_click", "compare_year", "compare_site","compare_var", "plotly_relayout-A", "FN", "EN", "ack", "sidebarCollapsed", "station_site", "station_year", "custom_year","custom_var"))
}
enableBookmarking("url")
shinyApp(ui, server)