I have the need to make a snapshot of a userdefined map using openstreet map in leaflet. I am using saveWidget to save a html file and then webshot to take a snap of that file. It works perfectly with Esri.WorldStreetMap and others. However, I cannot make it work with Openstreetmap. Below is a minimal exaple:
library(shiny)
library(leaflet)
library(webshot)
library(htmlwidgets)
ui <- fluidPage(
actionButton("button", "An action button")
)
server <- function(input, output, session) {
observeEvent(input$button,
{
themap<-leaflet() %>%
addProviderTiles("Openstreetmap.Mapnik")%>%
setView(lng=174.768, lat=-36.852,zoom=14)%>%
addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
saveWidget(themap, 'temp.html', selfcontained = T)
webshot('temp.html', file = "map.png",cliprect = viewport")
})
}
shinyApp(ui, server)