-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.Rmd
201 lines (139 loc) · 5.58 KB
/
index.Rmd
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
---
title: "Kerala Rainfall Forecast"
output:
flexdashboard::flex_dashboard:
theme: spacelab
vertical_layout: scroll
social: menu
source_code: embed
---
Last compiled on : `r format(Sys.time(), '%d %B, %Y')`
```{r setup, include=FALSE, warning=FALSE}
library(tidyverse)
library(sf)
library(lubridate)
library(flexdashboard)
library(leaflet)
library(formattable)
# load data
source("warn.R", local = knitr::knit_global())
map_in <- st_read("./data/kerala/kerala_lak.shp")
weather_a <- read_csv("./data/weather_warn.csv")
warning_code <- read_csv("./data/warning.csv")
# re-code
weather_a[weather_a == "No rain"] <- "No alert"
weather_a[weather_a == "L." ] <- "Green alert"
weather_a[weather_a == "L. to M" ] <- "Green alert"
weather_a[weather_a == "L to M" ] <- "Green alert"
weather_a[weather_a == "VL" ] <- "No alert"
weather_a[weather_a == "VL." ] <- "No alert"
weather_a[weather_a == "M" ] <- "Yellow alert"
weather_a[weather_a == "M." ] <- "Yellow alert"
weather_a[weather_a == "M. to H" ] <- "Yellow alert"
weather_a[weather_a == "M to H" ] <- "Yellow alert"
weather_a[weather_a == "ISOL. H" ] <- "Yellow alert"
weather_a[weather_a == "ISOL H. to VH" ] <- "Yellow alert"
weather_a[weather_a == "ISOL `H to VH" ] <- "Orange alert"
weather_a[weather_a == "H" ] <- "Orange alert"
weather_a[weather_a == "H." ] <- "Orange alert"
weather_a[weather_a == "`XH" ] <- "Orange alert"
weather_a[weather_a == "VH" ] <- "Red alert"
weather_a[weather_a == "VH." ] <- "Red alert"
weather_a[weather_a == "XH" ] <- "Red alert - Extremely heavy rainfall"
weather_a[weather_a == "XH." ] <- "Red alert - Extremely heavy rainfall"
weather_a[weather_a == "X H" ] <- "Red alert - Extremely heavy rainfall"
# col
colnames(weather_a)[1] <- "Name_1"
# shp + csv
map_latest <- merge(map_in,weather_a, by ="Name_1") %>%
filter(!grepl('Lakshadweep', Name_1))
# Col names
col2 <- sym(names(map_latest)[2])
col3 <- sym(names(map_latest)[3])
col4 <- sym(names(map_latest)[4])
col5 <- sym(names(map_latest)[5])
col6 <- sym(names(map_latest)[6])
col <- colnames(map_latest[2:6])
# Leaflet ideas-----
# maplatest copy
map_ker <- map_latest %>%
`colnames<-`(c("District","d1","d2","d3","d4","d5","geometry"))
# color factor
pal <-
colorFactor(palette = c('White', '#188f14', 'Yellow', 'Orange', 'Red', '#8B0000'),
levels = c("No alert","Green alert","Yellow alert","Orange alert",
"Red alert","Red alert - Extremely heavy rainfall"))
m <- leaflet(map_ker) %>%
addTiles() %>%
addPolygons(fillColor = pal(map_ker$District), fillOpacity = 0, color = "black") %>%
# Day 1
addPolygons(fillColor = pal(map_ker$d1), fillOpacity = .5,
popup = paste("Date: ",col2, "<br>",
"District: ",map_ker$District, "<br>",
"Rainfall alert: ", map_ker$d1, "<br>"), group = col[1]) %>%
# Day 2
addPolygons(fillColor = pal(map_ker$d2), fillOpacity = .5,
popup = paste("Date: ",col3, "<br>",
"District: ",map_ker$District, "<br>",
"Rainfall alert: ", map_ker$d2, "<br>") , group = col[2]) %>%
#Day 3
addPolygons(fillColor = pal(map_ker$d3), fillOpacity = .5,
popup = paste("Date: ",col4, "<br>",
"District: ",map_ker$District, "<br>",
"Rainfall alert: ", map_ker$d3, "<br>") , group = col[3]) %>%
# Day 4
addPolygons(fillColor = pal(map_ker$d4), fillOpacity = .5,
popup = paste("Date: ",col5, "<br>",
"District: ",map_ker$District, "<br>",
"Rainfall alert: ", map_ker$d4, "<br>") , group = col[4]) %>%
# Day 5
addPolygons(fillColor = pal(map_ker$d5), fillOpacity = .5,
popup = paste("Date: ",col6, "<br>",
"District: ",map_ker$District, "<br>",
"Rainfall alert: ", map_ker$d5, "<br>") , group = col[5]) %>%
setView(lng = 76.5711, lat = 10.5, zoom = 7) %>%
#addLegend(position = "bottomright",pal = pal,
#values = c("No alert","Green alert","Yellow alert","Orange alert",
#"Red alert","Red alert - Extremely heavy rainfall") ) %>%
addLayersControl(overlayGroups = col[1:5] ,
options = layersControlOptions(collapsed = T))%>%
# add inset map
addMiniMap(
tiles = providers$Esri.OceanBasemap,
position = 'bottomleft',
width = 120, height = 120,
toggleDisplay = FALSE)
```
Rainfall alert
=====================================
Column {.tabset }
-----------------------------------------------------------------------
### Rainfall Alert for the week - Weather Forecast for Kerala {.no-mobile}
```{r echo=FALSE }
# Rainfall Alert for the week - Weather Forecast for Kerala
m %>%
hideGroup(col[2:5])
```
### What does these alerts means ? {.no-mobile}
```{r}
formattable(warning_code[1:3]) %>%
na.omit()
```
Column {.tabset .mobile }
-----------------------------------------------------------------------
### Rainfall Alert for the week - Weather Forecast for Kerala
```{r echo=FALSE }
# Rainfall Alert for the week - Weather Forecast for Kerala
m %>%
hideGroup(col[2:5])
```
### What does these alerts means ?
```{r}
formattable(warning_code[1:3]) %>%
na.omit()
```
Info
=====================================
* Source: [IMD Trivandrum](https://mausam.imd.gov.in/thiruvananthapuram)
* All maps are generated automatically from the INDIAN METEOROLOGICAL DEPARTMENT bulletin.
* Complied by [Open-oven.github.io](https://Open-oven.github.io)