本文介绍了如何在Shiny中保存传单地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接着问题,我希望将传单地图保存并下载为png或jpeg图像.我有以下代码,但始终出现错误.

Following on from this question, I am looking to save and download a leaflet map as a png or jpeg image. I have the following code but I keep getting an error.

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)

我尝试下载(通过单击按钮)时遇到的错误是

The error I get when I try to download (by clicking the button) is

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进行操作,则奖励积分.

Bonus points if you can tell me how to get this working with 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)
        }
      )
    }

这篇关于如何在Shiny中保存传单地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 23:59