1

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":

enter image description here

  • 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!

3
  • A comment on the thread you link says that this Leaflet slider plugin is needed. I don't think knitr has anything to do with it---the other user was embedding the leaflet map in a knitr document, you're not. Commented Jul 28, 2022 at 19:51
  • Has nothing to do with knitr. Commented Jul 28, 2022 at 19:51
  • Thanks for your comments! I was looking at the github page for the leaflet slider: github.com/dwilhelm89/LeafletSlider - do you know how someone would install this?
    – stats_noob
    Commented Jul 28, 2022 at 19:53

1 Answer 1

0

Yes, but in your case, the output discrepancy has nothing to do with knitr.

NOTE: the OP (appropriately) opened another question asking how to implement a slider and so this is brief since it is directly answering the question.

Not the answer you're looking for? Browse other questions tagged or ask your own question.