无法使用savewidget / webshot在传单中快照Openstreetmap

时间:2017-10-31 09:26:17

标签: r shiny leaflet htmlwidgets

我需要使用传单中的openstreet map制作用户定义地图的快照。我正在使用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)

1 个答案:

答案 0 :(得分:1)

稍作修改,您的代码就可以在我的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)

这就是我得到的:

enter image description here