rr-mapview

Mapview Popup Graph Appear on Hover?


Is there a way to make popup graphs appear on hover (rather than click) in Mapview? Alternatively, is it possible for the graphs to appear open by default? Rather than produce my own reproducible example, I would defer to the example given with the R Mapview documentation.

I am fairly new to R and Mapview so any guidance is greatly appreciated!


Solution

  • I've just pushed an update to package leafpop which provides the popup functionality used in mapview. This should provide what you want (at least partly - as mapview() will still need to be updated). This allows you to now specify tooltip = TRUE in addPopupImages (in addPopupGraphs via ...). Note that it is encouraged to use addPopup* functions over the classic popup* functions because they also work in non-interactive setting, e.g. when saving a map locally.

    library(sf)
    library(leaflet)
    library(lattice)
    library(leafpop)
    
    pt = data.frame(x = 174.764474, y = -36.877245)
    pt = st_as_sf(pt, coords = c("x", "y"), crs = 4326)
    
    p2 = levelplot(t(volcano), col.regions = terrain.colors(100))
    
    leaflet() %>%
      addTiles() %>%
      addCircleMarkers(data = pt, group = "pt") %>%
      addPopupGraphs(
        list(p2)
        , group = "pt"
        , width = 300
        , height = 400
        , tooltip = TRUE
      )
    

    Not sure when and how to integrate this into mapview() as this is a bit more complicated than the classic popup* functions (because we need to know something about the map object we create with mapview before we create it...). In any case, I hope this is at least partly useful and helps resolve your issue.