首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用savewidget/webshot在leaflet中创建Openstreetmap快照

无法使用savewidget/webshot在leaflet中创建Openstreetmap快照
EN

Stack Overflow用户
提问于 2017-10-31 17:26:17
回答 1查看 213关注 0票数 0

我需要制作一个用户定义的地图快照使用openstreet地图在宣传单。我正在使用saveWidget来保存一个html文件,然后使用webshot来拍摄该文件的快照。它可以与Esri.WorldStreetMap和其他软件完美地协同工作。但是,我不能让它与Openstreetmap一起工作。下面是一个最小的例子:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2017-10-31 19:09:17

只需稍加修改,您的代码就可以在我的R 3.4.2上运行:

代码语言:javascript
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47031902

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档