gpt4 book ai didi

r - 如何在 Shiny 中保存传单 map

转载 作者:行者123 更新时间:2023-12-01 08:15:05 25 4
gpt4 key购买 nike

this问题,我想将传单 map 保存和下载为 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 进行此操作,则可以加分。 .

最佳答案

可能这会有所帮助:

  server <- function(input, output, session) {

map <- reactiveValues(dat = 0)

output$map <- renderLeaflet({
map$dat <- leaflet() %>%
addTiles()
})

output$dl <- downloadHandler(
filename = "map.png",

content = function(file) {
mapshot(map$dat, file = file)
}
)
}

关于r - 如何在 Shiny 中保存传单 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44259716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com