Last compiled on : 21 November, 2024
Source: IMD Trivandrum
All maps are generated automatically from the INDIAN METEOROLOGICAL DEPARTMENT bulletin.
Complied by Open-oven.github.io
---
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)