Problem
I have regular raster data with a time dimension. It comes as a stars object with the dimensions x, y, date.
I want to visualize the stars raster with a timeslider (like this one or similar) - to show every point in time.
Unfortunately mapview cannot handle the time dimension out of the box, maybe a plain leaflet solution or even a shiny app is needed to do that.
Any ideas?
Reproducible Example
library(stars)
library(mapview)
n <- 2
df <- data.frame(
x = rep(rep(c(1:n), times = n), times = n),
y = rep(rep(c(1:n), each = n), times = n),
value = seq(1:(n * n * n)),
date = rep(seq(
as.Date("2023-01-01"), by = "day", length.out = n
), each = n * n)
)
df
# x y value date
# 1 1 1 1 2023-01-01
# 2 2 1 2 2023-01-01
# 3 1 2 3 2023-01-01
# 4 2 2 4 2023-01-01
# 5 1 1 5 2023-01-02
# 6 2 1 6 2023-01-02
# 7 1 2 7 2023-01-02
# 8 2 2 8 2023-01-02
# Create stars object with time dimension from df
stars_with_time <- stars::st_as_stars(df,
dims = c("x", "y", "date"))
# assign arbitrary crs
stars_with_time <- st_set_crs(stars_with_time, 25833)
# Now mapview disregards the time dimension
mapview(stars_with_time)
