【发布时间】:2016-07-29 11:22:41
【问题描述】:
我创建了一个应用程序,用户可以在其中修改传单地图,我想在 pdf 报告中使用此地图。我有 1.安装包leaflet、webshot和htmlwidget 2.安装PhantomJS
下面是简化版的代码
服务器.R:
library(shiny)
library(leaflet)
library(htmlwidgets)
library(webshot)
shinyServer(function(input, output, session) {
output$amap <- renderLeaflet({
leaflet() %>%
addProviderTiles("Stamen.Toner",
options = providerTileOptions(noWrap = TRUE, reuseTiles=TRUE))
})
observe({
leafletProxy("amap") %>%
clearShapes() %>%
addCircles(lng = c(22,-2), lat = c(42,65))
})
observeEvent(input$saveButton,{
themap<- leafletProxy("amap")
saveWidget(themap, file="temp.html", selfcontained = F)
webshot("temp.html", file = "Rplot.png",
cliprect = "viewport")
})
})
ui.R:
fluidPage(
leafletOutput("amap", height="600px", width="600px"),
br(),
actionButton("saveButton", "Save")
)
我收到此错误消息:
警告:system.file 中的错误:“包”的长度必须为 1 堆栈跟踪(最内层优先): 73:系统文件 72:读取线 71:粘贴 70:yaml.load 69: yaml::yaml.load_file 68:获取依赖关系 67:小部件_依赖项 66: htmltools::attachDependencies 65:转HTML 64:保存小部件 63:observeEventHandler [C:\R 文件\test/server.R#24] 1:闪亮::runApp
当保存按钮被激活时。 当我像这样定义保存按钮时,savewidget 工作正常:
observeEvent(input$saveButton,{
themap<-leaflet() %>%
addProviderTiles("Stamen.Toner",
options = providerTileOptions(noWrap = TRUE, reuseTiles=TRUE))
saveWidget(themap, file="temp.html", selfcontained = F)
webshot("temp.html", file = "Rplot.png",
cliprect = "viewport")
})
但我真的想要用户在 webshot 中所做的更改。有人可以帮忙吗?
【问题讨论】:
-
您希望用户能够保存文件吗?我认为这在 JavaScript 方面会更好地处理。我会试着为你做一个例子。
-
好吧,我出色的解决方案陷入了跨域问题。我会试着想其他的处理方式。