I am trying to follow this post on stackoverflow (R Leaflet: Add a Range Slider to Filter Markers without Shiny). I copy and pasted the code below:
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()
Yet when I run this code, the resulting map is missing the "slider":
- Does anyone know why this is happening? Is this because the "slider" requires the "knitr" package? Is it possible I might have to save this map as an "html" file for the slider to appear?
Thank you!
knitr
has anything to do with it---the other user was embedding the leaflet map in a knitr document, you're not.knitr
.