r-spatial / leafpop

Include Tables, Images and Graphs in Leaflet Popups
Other
113 stars 15 forks source link

htmlwidgets::saveWidget() doesn't work nested popup #5

Closed leungi closed 3 years ago

leungi commented 5 years ago

This is taken from the package example.

The resulting html doesn't load the content in popupGraph(). Is there a way to embed, say, via an embed argument in popupGraph().

library(leaflet)
library(leafpop)

leaflet() %>%
  addTiles() %>%
  addCircleMarkers(
    data = breweries91[1, ],
    popup = popupGraph(
      leaflet() %>%
        addProviderTiles("Esri.WorldImagery") %>%
        addMarkers(data = breweries91[1, ],
                   popup = popupTable(breweries91[1, ])),
      type = "html"
    )
  ) %>% 
  htmlwidgets::saveWidget('pop_nested.html', selfcontained = TRUE)
tim-salabim commented 5 years ago

I am currently working on a solution (addPopupIframes/addPopupWidgets) that should make this possible. I hope to have this working soon.

tim-salabim commented 3 years ago

So, after ages (sorry!) here's a solution that works. Some things to note:

Still an unexported function, as I am still not happy with the general implementation.

library(leaflet)
library(leafpop)
library(sp)

pop_map = leaflet() %>%
  addProviderTiles(
    "Esri.WorldImagery"
  ) %>%
  addMarkers(
    data = breweries91[1, ]
    , popup = popupTable(breweries91[1, ])
  )

fl = tempfile(fileext = ".html")
htmlwidgets::saveWidget(
  pop_map
  , file = fl
)

pop_nested = leaflet() %>%
  addTiles(group = "OSM") %>%
  addCircleMarkers(
    data = breweries91[1, ]
    , group = "brew1"
  ) %>%
  leafpop:::addPopupIframes(
    source = fl
    , group = "brew1"
  )

htmlwidgets::saveWidget(
  pop_nested
  , '/home/timpanse/Downloads/pop_nested.html'
  , selfcontained = FALSE
)

Closing this. If there are other requests like this one, please open a new issue.

leungi commented 3 years ago

No worries; thanks for the update 🙏

Tested it and looks promising; we have a solution for now 🙌