File size: 1,674 Bytes
267753b 8e0c83c 267753b 8e0c83c 267753b 8e0c83c 267753b 8e0c83c |
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 |
library(shiny) # for shiny apps
library(leaflet) # renderLeaflet function
library(spData) # loads the world dataset
library(terra)
library(stars)
library(leaflet.extras2)
ui = fluidPage(
leafletOutput(outputId = "map")
)
before_fire_tifs <- "/vsicurl/https://huggingface.co/spaces/cboettig/shiny-app/resolve/main/before_fire/cube_d36238205702022-05-25.tif"
after_fire_tifs <- "/vsicurl/https://huggingface.co/spaces/cboettig/shiny-app/resolve/main/after_fire/cube_d36482e5462022-05-30.tif"
before_fire_nbr <- read_stars(before_fire_tifs)
after_fire_nbr <- read_stars(after_fire_tifs)
dnbr <- before_fire_nbr - after_fire_nbr
server = function(input, output) {
output$map = renderLeaflet({
#https://trafficonese.github.io/leaflet.extras2/reference/addSidebyside.html
# addRasterImage options requires pre-release leaflet....
stopifnot(compareVersion(as.character(packageVersion("leaflet")), "2.2.1") > 0)
Map <- leaflet() |>
addMapPane("right", zIndex = 0) |>
addMapPane("left", zIndex = 0) |>
addTiles(group = "base", layerId = "baseid1", options = pathOptions(pane = "right")) |>
addTiles(group = "base", layerId = "baseid2", options = pathOptions(pane = "left")) |>
addRasterImage(x = rast(after_fire_nbr), options = leafletOptions(pane = "right"), group = "r1") |>
addRasterImage(x = rast(before_fire_nbr), options = leafletOptions(pane = "left"), group = "r2") |>
addLayersControl(overlayGroups = c("r1", "r2")) |>
addSidebyside(layerId = "sidecontrols",
rightId = "baseid1",
leftId = "baseid2")
})
}
shinyApp(ui, server)
|