继承于这个问题,我想要将一个leaflet地图保存并下载成png或jpeg格式的图片。我有以下代码但是一直收到错误信息。
ui <- fluidPage(
leafletOutput("map"),
downloadButton("dl")
)
server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet() %>%
addTiles()
})
output$dl <- downloadHandler(
filename = "map.png",
content = function(file) {
mapshot(input[["map"]], file = file)
}
)
}
shinyApp(ui = ui, server = server)
当我尝试通过点击按钮下载时,出现的错误是:
Warning: Error in system.file: 'package' must be of length 1
Stack trace (innermost first):
65: system.file
64: readLines
63: paste
62: yaml.load
61: yaml::yaml.load_file
60: getDependency
59: widget_dependencies
58: htmltools::attachDependencies
57: toHTML
56: <Anonymous>
55: do.call
54: mapshot
53: download$func [#11]
4: <Anonymous>
3: do.call
2: print.shiny.appobj
1: <Promise>
Error : 'package' must be of length 1
如果您能告诉我如何在
leafletProxy
中使用这一功能,那就更好了。
renderPrint({reactiveValuesToList(input)})
,在UI界面上使用verbatimTextOutput
来查看所有可用的输入。那就是我看到input$map_center
选项的地方。 - Hallie Swan