-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
70 lines (58 loc) · 1.68 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
library(shiny)
library(sf)
library(raster)
library(dplyr)
library(stringr)
library(leaflet)
rasters = list.files("./plots/hatchraster/", "(.tif)", full.names = TRUE)
rasters=rasters[!grepl('aux.xml', rasters)]
rdates = as.Date(str_extract(rasters, "\\d+(?=.tif)"), "%Y%m%d")
# Define UI for app that draws a histogram ----
ui <- fluidPage(
absolutePanel(
top = 0,
bottom = 0,
left = 0,
right = 0,
leafletOutput(height = "100%", outputId = "map")
),
HTML('<br>'),
column(
width = 3,
offset = 9,
selectInput(
inputId = "date",
label = 'Simulation date',
choices = rdates,
selected = max(rdates)
)
)
)
# Define server logic required to draw a histogram ----
server <- function(input, output) {
output$map <- renderLeaflet({
hatch = raster(rasters[which(rdates == input$date)])
h = hatch[]
# plot model output
currentday = max(rdates) %>%
format("%j") %>% as.numeric()
hatchtime = tibble(hatchtime = h - currentday) %>%
mutate(buckets = case_when(hatchtime < -14 ~ 1,
hatchtime <= 0 ~ 2,
hatchtime > 0 ~ 3)) %>%
pull(buckets)
hatch[] = hatchtime
hatch[h == 0] = NA
labs = c(
"hatched more than 2 weeks ago",
"hatched less than 2 weeks ago",
"hatching in coming weeks"
)
pal = RColorBrewer::brewer.pal(3, "Pastel1")
leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addRasterImage(hatch, colors = pal, opacity = 0.7) %>%
addLegend(position = "bottomleft", colors = pal, labels = labs)
})
}
shinyApp(ui = ui, server = server)