我正在尝试关注 stackoverflow 上的这篇文章(R Leaflet:Add a Range Slider to Filter Markers without Shiny)。我复制并粘贴以下代码:
library( crosstalk )
library( leaflet )
library( dplyr )
data <- data.frame(id = c(1,2,3,4,5),
lat= c(50.9, 50.8, 50.5, 50.5, 51),
lon = c(-0.7, -0.92, -1, -0.8, -0.9),
date = c("2020-06-01", "2020-05-07", "2020-03-24", "2020-04-01", "2020-05-26"))
data <- data %>% dplyr::mutate( date2 = as.numeric( as.Date( date ) ),
date3 = as.Date( date )
)
shared_data <- SharedData$new( data )
filter_slider("date", "Date", shared_data, ~date3, width = "100%")
leaflet(shared_data, width = "100%", height = 800) %>%
leaflet::addTiles() %>%
leaflet::addMarkers()
然而,当我运行此代码时,生成的地图缺少“滑块”: