3

How can a popup stay open when clicking on another?

The MWE below show a popup when I click on the markers. Good. But when I click on a second marker I don't want the first popup to disappear. It should only disapear when clicking the close [x]. No popups should be visible before clicking on the markers.

library(leaflet)
the.points <- data.frame(latitude=c(63.136353,63.132935,63.128051),
  longitude=c(21.928023,21.962601,21.893444),
  text=c("One point", "A second point", "The third point"))
p <- leaflet(the.points)
p <- addTiles(p)
p <- addMarkers(p, lng=~longitude, lat=~latitude, popup=~text)
p

I tried with addPopups too, but they are all visible by default. If that can be changed it would be good (not sure how).

Chris
  • 2,256
  • 1
  • 19
  • 41
  • it's possible with leaflet (closePopupOnClick) http://leafletjs.com/reference.html#map-options but I don't think it was implemented in R leaflet. I hope I am wrong :-) – MLavoie Feb 09 '16 at 17:22
  • Looks like you are right... – Chris Feb 10 '16 at 20:56

1 Answers1

3

Was struggling with the same thing, finally this worked for me:

leaflet() %>% addTiles() %>%
  addMarkers(
    lng = -118.456554, lat = 34.085,
    popup = "One popup",
    popupOptions = popupOptions(autoClose = FALSE, closeOnClick = FALSE)) %>%
  addMarkers(
    lng = -118.456554, lat = 34.065,
    popup = "Another popup",
    popupOptions = popupOptions(autoClose = FALSE, closeOnClick = FALSE))
  )
eh21
  • 629
  • 7
  • 7