我需要制作一个用户定义的地图快照使用openstreet地图在宣传单。我正在使用saveWidget来保存一个html文件,然后使用webshot来拍摄该文件的快照。它可以与Esri.WorldStreetMap和其他软件完美地协同工作。但是,我不能让它与Openstreetmap一起工作。下面是一个最小的例子:
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)发布于 2017-10-31 19:09:17
只需稍加修改,您的代码就可以在我的R 3.4.2上运行:
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)这是我得到的:

https://stackoverflow.com/questions/47031902
复制相似问题