-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherased.txt
348 lines (259 loc) · 13.5 KB
/
erased.txt
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
Indikátory sucha {data-icon="fa-tint"}
=====================================
Column {.sidebar data-width=400}
-----------------------------------------------------------------------
```{r indikatory: sidebar}
help_text_vzorec <- c(
spi = "",
spei = "",
# pdsi = "",
scpdsi = "",
PP = "$$PP = \\frac{PET}{P}$$",
WQ90 = "$$WQ90 = \\frac{POV+POD+MZP}{Q90}$$",
WPP = "$$WPP = \\frac{POV+POD+MZP}{P-PET}$$",
WQ90_ = "$$WQ90\\_ = \\frac{POV+POD-VYP+MZP}{Q90}$$",
WPP_ = "$$WPP\\_ = \\frac{POV+POD-VYP+MZP}{P-PET}$$ ",
prum = "prùmìr indexù PP, WPP_ a WQ90_")
renderUI({
wellPanel(
selectizeInput(inputId = "search.id.ind","Vyhledávání útvaru",
selected=input$indikator_shape_click$id,
choices = search.choices)
)
})
wellPanel(
radioButtons("indikatory", label=NULL, choices = c("PDSI" = "pdsi",
"scPDSI" = "scpdsi", "SPEI" = "spei", "SPI" = "spi",
"PP", "WQ90", "WPP", "WQ90_", "WPP_",
"prùmìry zranitelnosti" = "prum"),
# "PDSI" = "C", "SGI" = "D", "SRI" = "E", "Nedostatkové objemy" = "F"),
selected = "scpdsi"),
conditionalPanel(condition = "input.indikatory == 'spi' || input.indikatory == 'spei' || input.indikatory == 'pdsi'",
selectInput("krok", label = NULL, choices = c("1 mìsíc" = 1, "3 mìsíce" = 3,
"6 mìsícù" = 6, "12 mìsícù" = 12), selected = 3)),
conditionalPanel(condition = "input.indikatory == 'spi'",
selectInput("entry.variable.ind", label=NULL, selected = "P",
choices = c('P', 'R', 'RM', 'BF'))),
conditionalPanel(condition = "input.indikatory == 'spi' || input.indikatory == 'spei'|| input.indikatory == 'scpdsi'",
dateInput("entry.date.ind", label = NULL, "yyyy-mm-dd", language = "cs",
value = as.Date("1985-01-01"), startview = "decade",
min = as.Date("1961-01-01"), max = as.Date("2018-06-01")), #2015-12-01
hr(),
HTML(paste("<b>SPI & SPEI: </b> 1961-01-01 až 2018-06-01 <br> <b>scPDSI: </b> 1961-01-01 až 2015-12-01"))
)
)
renderUI({
if(input$indikatory %in% c("PP","WQ90","WPP","WPP_","prum","WQ90_")){
wellPanel(
withMathJax(help_text_vzorec[input$indikatory]),
hr(),
HTML(paste("PET - potenciální evapotranspirace",
"P - srážky",
"POV - odbìry z povrchových vod",
"POD - odbìry z podzemních vod",
"VYP - vypouštìní (databáze VÚV TGM, v.v.i.)",
"MZP - minimální zùstatkový prùtok",
"Q90 - 90% kvantil prùtoku", sep = "<br>"))
)
}
})
wellPanel(checkboxGroupInput("entry.layer.ind", label = "Vrstvy",
choices = c("Mapový podklad" = "MP", "Povodí" ="P", "Øeky" = "R", "Jezera" = "J",
"Nádrže" = "N", "Kraje" = "K", "Okresy" = "O", "Povodí 3. øádu" = "P3"),
selected = c("MP", "P"),
inline = T))
div(style="display:inline-block",
actionButton("reset_button2", "Reset", icon("arrows"),
style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),
actionButton("go2", "Zobrazit", icon("check"),
style="color: #fff; background-color: #337ab7; border-color: #2e6da4")
)
```
```{r indikatory: Reactions}
#help-------------------------
# default.shape.ind <- function(){return("DUN_0010")}
# input<-c()
# input$indikatory = "spi"
# input$entry.variable.ind = "P"
# input$krok = 3
# input$entry.date.ind <- as.Date("1961-01-01")
#Reactions--------------------
reac.ind <- eventReactive(input$go2,{
vrstvy <- input$entry.layer.ind
if(input$indikatory %in% c("spi", "spei")){
ind_dta <- readRDS(file.path(.datadir,"webapp_data/indikatory_2015", paste0(input$indikatory, "_", input$krok, ".rds")))
}else if(input$indikatory %in% c("scpdsi", "pdsi")){ #"pdsi",
ind_dta <- readRDS(file.path(.datadir,"indikatory", paste0(input$indikatory, ".rds")))
}else{
ind_dta <- IND %>% select(UPOV_ID, value = input$indikatory)
}
#Dlouhodobé prùmìry (celé období/vybrané období)
if(input$indikatory == "spi"){
ind_dta_f <- ind_dta[ind_dta$variable == input$entry.variable.ind, ]
dta <- (sp::merge(povodi, ind_dta_f[ind_dta_f$year == year(input$entry.date.ind) & ind_dta_f$month==month(input$entry.date.ind), ],
by="UPOV_ID"))
}else if(input$indikatory %in% c("spei", "scpdsi", "pdsi")){ #"pdsi",
ind_dta_f <- ind_dta
dta <- (sp::merge(povodi,ind_dta_f[ind_dta_f$year == year(input$entry.date.ind) & ind_dta_f$month==month(input$entry.date.ind), ],
by="UPOV_ID"))
}else{
ind_dta_f <- ind_dta
dta <- sp::merge(povodi, ind_dta, by="UPOV_ID")
}
#Vytvaøení palet
# (2,0 až inf) - tmave modra
# (1,4 až 2,0) - modra
# (0,5 až 1,4) - svetle zelena
# (-0,5 až 0,5) - neutralni
# (-0,5 až -1,4) - zluto oranzova (+-)
# (-1,4 až -2,0) - cervena
# (- 2,0 až -inf) - tmave èervena
mojePaleta <- c("#800000", "#ff0000", "#feb316", "#eafe9a", "#99ff66", "#0066ff", "#000066")
if(input$indikatory %in% c("spi", "spei", "pdsi", "scpdsi")){
pal <- colorBin(mojePaleta, domain = dta$value, bins = c(Inf, 2, 1.4, 0.5, -0.5, -1.4, -2, -Inf),
na.color = "#999999")
}else if(input$indikatory == "PP"){
pal <- colorBin(mojePaleta, domain = dta$value, bins = c(1000, 1, 0.9, 0.6, -1000),
na.color = "#999999")
}else if(input$indikatory == "WPP"){
pal <- colorBin(mojePaleta, domain = dta$value, bins = c(1000, 5, 3, 1, 0),
na.color = "#999999")
}else if(input$indikatory == "WQ90"){
pal <- colorBin(mojePaleta, domain = dta$value, bins = c(1000, 10, 5, 2, 0),
na.color = "#999999")
}else if(input$indikatory == "WPP_"){
pal <- colorBin(mojePaleta, domain = dta$value, bins = c(1000, 5, 1, 0, -100),
na.color = "#999999")
}else if(input$indikatory == "WQ90_"){
pal <- colorBin(mojePaleta, domain = dta$value, bins = c(1000, 10, 2, 0, -1000),
na.color = "#999999")
}else if(input$indikatory == "prum"){
pal <- colorBin(mojePaleta, domain = dta$value, bins = c(4.5, 3.5, 2.5, 1.5, 0.5),
na.color = "#999999")
}
return(list(vrstvy = vrstvy, dta=dta, ind_dta_f = ind_dta_f, pal = pal))
}, ignoreNULL = FALSE, ignoreInit = FALSE)
```
Row
-------------------------------------
```{r indikatory: mapa}
#Functions--------------------
default.shape.ind <- reactive({
if(is.null(input$search.id.ind)){
UPOV_ID.sel <- "BER_0010"
}else{
UPOV_ID.sel <- input$search.id.ind}
return(UPOV_ID.sel)})
# default.shape.ind <- reactive({
# UPOV_ID.sel <- input$search.id.ind
# return(UPOV_ID.sel)})
initial_lat = 49.7437572
initial_lng = 15.3386383
initial_zoom = 7
#Outputs
#Leaflet--------------------
output$indikator <-renderLeaflet({
reac.ind_app <- reac.ind()
dta <- reac.ind_app$dta
pal <- reac.ind_app$pal
vrstvy <- reac.ind_app$vrstvy
# Creating labels--------------------
labels <- sprintf(
"<strong>%s</strong><br/>Kategorie: %s<br/>Stav: %s <br/> UPOV_ID: %s <br/> Hodnota: %s",
dta$NAZ_UTVAR, dta$KTG_UPOV, dta$U_PMU, dta$UPOV_ID, round(dta$value,2)
) %>% lapply(htmltools::HTML)
if(length(labels)==0){labels <- c(" ")}
indikatory <- leaflet() %>%
setView(lat = initial_lat, lng = initial_lng, zoom = initial_zoom)
#Zbarvení povodí dle hodnoty
if("P" %in% vrstvy){ #addPolygons
indikatory <- indikatory %>% addPolygons(data=dta, layerId = dta$UPOV_ID, color = "black",
weight = 1.5, opacity = 0.45, smoothFactor = 0,
fillColor = ~pal(value), fillOpacity = 0.5,
group = "Povodí",
highlightOptions = highlightOptions(color = "#a53333",
opacity = 1,
fillOpacity = 0,
weight = 2.3,
bringToFront = TRUE, sendToBack = TRUE),
label = labels,
labelOptions = labelOptions(clickable = TRUE,
style = list("font-weight" = "normal",
"font-family" = "sans-serif", padding = "3px 8px",
keepInView = TRUE, noHide = FALSE,
"border-color" = "rgb(255, 255, 255)"),
textsize = "13px", direction = "auto"))%>%
addLegend(pal = pal, values = dta$value, opacity = 0.7, title = "Legenda",
position = "bottomright")}
if("MP" %in% vrstvy){
indikatory <- indikatory %>% addTiles(group = "Mapový podklad", options = tileOptions(minZoom=7, maxZoom=13))
}
if("R" %in% vrstvy){ #addPolylines
indikatory <- indikatory %>% addPolylines(data=reky, color="#007C8C", weight = 1.5,
opacity = 1, stroke= TRUE, group = "Øeky")
}
if("J" %in% vrstvy){ #addPolygons
indikatory <- indikatory %>% addPolygons(data=jezera, color="#007C8C", fillColor = "#0099ff",
weight = 1, opacity = 1, stroke= TRUE, group = "Jezera")}
if("N" %in% vrstvy){ #addPolygons
indikatory <- indikatory %>% addPolygons(data=nadrze, color="#007C8C", fillColor = "#0099ff",
weight = 1, opacity = 1, stroke= TRUE, group = "Nádrže")}
if("K" %in% vrstvy){ #addPolylines
indikatory <- indikatory %>% addPolylines(data=kraje, color="#000000", weight = 2.5, fill=F,
stroke= TRUE, group = "Kraje")}
if("O" %in% vrstvy){ #addPolylines
indikatory <- indikatory %>% addPolylines(data=okresy, color="#000000", weight = 2, fill=F,
stroke= TRUE, group = "Okresy")}
if("P3" %in% vrstvy){
indikatory <- indikatory %>% addPolylines(data=povodi_III, color="#cc0000", weight = 2.5, opacity = 1,
stroke= TRUE, group = "Povodí 3. øádu")
}
print(indikatory)
})
#Zvyraznìní souèasného povodí
observe({
leafletProxy("indikator") %>%
clearGroup("current_shape") %>%
addPolylines(data = subset(povodi,
UPOV_ID==(if(is.null(input$search.id.ind)){"BER_0010"}else{input$search.id.ind})),
group = "current_shape",
color = "#a53333", opacity = 1, weight = 3,
stroke = TRUE)
})
#Reset button
observe({
input$reset_button2
leafletProxy("indikator") %>% setView(lat = initial_lat, lng = initial_lng, zoom = initial_zoom)})
leafletOutput("indikator")
```
Row
-------------------------------------
```{r indikatory: TS}
renderDygraph({
if(input$indikatory %in% c("spi", "spei", "scpdsi", "pdsi")){ #"pdsi",
ind_dta_f <- reac.ind()$ind_dta_f
ts.indikatory <- ind_dta_f[ind_dta_f$UPOV_ID == default.shape.ind(), ] %>% select(value, DTM)
if(nrow(ts.indikatory) != 0){
RangeMin <- min(ts.indikatory$value, na.rm = T)-0.5
RangeMax <- max(ts.indikatory$value, na.rm = T)+0.5
ts.indikatory$value[is.na(ts.indikatory$value)]<-0
ts.indikatory <- xts::xts(ts.indikatory, order.by = ts.indikatory$DTM)
dygraph(ts.indikatory,
main = paste(as.character(popis$NAZ_UTVAR[popis$UPOV_ID==default.shape.ind()])),
xlab = "Èas") %>%
dyAxis("y", valueRange = c(RangeMin, RangeMax)) %>%
dyLimit(0, strokePattern = "solid", color = "black") %>%
dyOptions(colors = "gray", fillGraph = TRUE, fillAlpha = 0.4) %>%
dyLegend(width = 400, show = "always", hideOnMouseOut = FALSE)
}else{
ts.indikatory <- data.frame(DTM = seq(Sys.Date()-4, Sys.Date(), 1), value = rep(0,5))
ts.indikatory <- xts::xts(ts.indikatory, order.by = ts.indikatory$DTM)
dygraph(ts.indikatory, xlab = "Èas",
main = paste(as.character(popis$NAZ_UTVAR[popis$UPOV_ID==default.shape.ind()]))) %>%
dySeries("value", label = "Nejsou záznamy") %>%
dyOptions(colors = "gray", fillGraph = TRUE, fillAlpha = 0.4) %>%
dyLegend(width = 400, show = "always", hideOnMouseOut = FALSE)
}
}else{}
})
```