首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么webshot不适用于R shiny中的传单?

为什么webshot不适用于R shiny中的传单?
EN

Stack Overflow用户
提问于 2016-11-29 03:48:23
回答 1查看 1K关注 0票数 5

首先,webshot在我得到的webshot("www.google.com")的上下文webshot("google.com")中不起作用:

代码语言:javascript
复制
        env: node\r: No such file or directory
        Error in webshot("google.com") : webshot.js returned failure value: 127

所以这对leaftlet代码不起作用

代码语言:javascript
复制
    staters <<-    
   readOGR(dsn="cb_2015_us_county_20m",layer="cb_2015_us_county_20m")
  getMap<-function()({

leaflet(staters) %>%
  addPolygons( stroke = T, fillOpacity =.7, smoothFactor = 0, color = "black",
               weight = .5, fill = T, fillColor = "red"
  )
output$downloadMap <- downloadHandler(
filename = function() { paste(input$chooseStates, '.png', sep='') },
content = function(file) {
  # temporarily switch to the temp dir, in case you do not have write
  # permission to the current working directory
  owd <- setwd(tempdir())
  on.exit(setwd(owd))

  saveWidget(getMap(), "temp.html", selfcontained = FALSE)
  webshot("temp.html", file = "filename.png", cliprect = "viewport")
}

)

当我在rshiny上运行这个命令时,我得到了一个404错误

EN

回答 1

Stack Overflow用户

发布于 2018-06-15 19:35:48

它起作用了。我认为您错过了在downloadHandler中将file参数传递给webshot

我将叶地图保存在reactive中,然后您可以在renderLeafletdownloadHandler中调用它。

下面的示例应该可以工作:

代码语言:javascript
复制
## install 'webshot' package
library(devtools)
# install_github("wch/webshot")
## load packages
# install_phantomjs(version = "2.1.1",
#                   baseURL = "https://github.com/wch/webshot/releases/download/v0.3.1/")
library(leaflet)
library(htmlwidgets)
library(webshot)
library(shiny)

ui <- fluidPage(
  leafletOutput("map"),
  downloadLink("downloadMap", "Download")
)

server <- function(input,output) {
  mapReact <- reactive({
    leaflet() %>% 
      addTiles('http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png') %>% 
      addCircles(12.5,42,radius=500) %>% addMarkers(12,42,popup="Rome")
  })

  output$map <- renderLeaflet({
    mapReact()
  })

  output$downloadMap <- downloadHandler(
    filename = paste("LeafletMap", '.png', sep=''),
    content = function(file) {
      owd <- setwd(tempdir())
      on.exit(setwd(owd))
      saveWidget(mapReact(), "temp.html", selfcontained = FALSE)
      webshot("temp.html", file = file, cliprect = "viewport")

    })
}

shinyApp(ui, server)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40852314

复制
相关文章

相似问题

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