我创建了一个应用程序,用户可以修改leaflet地图,我想在PDF报告中使用此地图。我已经:
1. 安装了leaflet、webshot和htmlwidget包
2. 安装了PhantomJS
以下是简化版本的代码。
我得到了这个错误消息:
警告:Error in system.file: 'package' 必须是长度为 1 的向量 堆栈追踪(最内层的先显示): 73: system.file 72: readLines 71: paste 70: yaml.load 69: yaml::yaml.load_file 68: getDependency 67: widget_dependencies 66: htmltools::attachDependencies 65: toHTML 64: saveWidget 63: observeEventHandler [C:\R files\test/server.R#24] 1: shiny::runApp 当保存按钮被激活时。 如果我像这样定义保存按钮,savewidget 就可以正常工作:
但我真的希望用户在网页截图中所做的更改能够被保留下来。有人可以帮忙吗?
以下是简化版本的代码。
server.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")
)
我得到了这个错误消息:
警告:Error in system.file: 'package' 必须是长度为 1 的向量 堆栈追踪(最内层的先显示): 73: system.file 72: readLines 71: paste 70: yaml.load 69: yaml::yaml.load_file 68: getDependency 67: widget_dependencies 66: htmltools::attachDependencies 65: toHTML 64: saveWidget 63: observeEventHandler [C:\R files\test/server.R#24] 1: shiny::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")
})
但我真的希望用户在网页截图中所做的更改能够被保留下来。有人可以帮忙吗?