Keep Leaflet Popup in View (R)

Viewed 202

I'm building a dashboard which has a Leaflet visualisation. When an area is clicked, a rather large popup with a picture and information is displayed, as below (information is blurred because data is proprietary):

image of leaflet map with popup

However, depending on where the user clicks on the map, the popup may be cut off, as below:

image of leaflet map with cut-off popup

I want the popup to always be in view when the user clicks, i.e. no cutting off. Calling

popupOptions = popupOptions(keepInView = T)

seems to only work intermittently at best. I don't know much JS, so I'm not sure how to make it work.

I can't include a code example for aforementioned reasons, but the popup is called as follows:

leaflet() %>%
addPolygons(
  popup = paste0(*popup content*),
  popupOptions = popupOptions(keepInView = T)
)
0 Answers
Related