I am trying to export into png, jpg, or ANY format that can be saved, emailed, etc, a simple leaflet map with an icon made from a jpg file. Every method I tried based on suggestions like htmlwidgets, or mapview, gives me a file with only the icon on gray background (map layer gone). Then something weird happens. Even if I get rid of the custom icon (from my jpeg), now I get the gray background with the blue default icon, still no map.
I have tried every solution at How to save Leaflet in R map as png or jpg file? , I at best get the icon layer but no map.
library(leaflet)
anna1Icon <- makeIcon(
iconUrl = "pic.jpg",
iconWidth = 2*31*215/230, iconHeight = 2*31,
iconAnchorX = 2*31*215/230/2, iconAnchorY = 2*16
)
my_map <- leaflet() %>%
addTiles() %>%
addMarkers(lat=44, lng=-93, popup="House", icon = anna1Icon)
Solution attempt 1:
library(mapview)
mapshot(my_map, file = 'file.png')
Solution attempt 2:
library(htmlwidgets)
saveWidget(my_map, file="temp.html", selfcontained = FALSE)
webshot("temp.html", file = "output.png",
cliprect = "viewport")
Help, thank you!