Return a rendered leaflet map from leafletProxy()

為{幸葍}努か 提交于 2019-12-13 02:27:34

问题


Is it possible to retrieve a leaflet map in Shiny after it's already been rendered?

Here is an example in code that shows how a map generated by leaflet() is different from one that is returned from leafletProxy() even though they would appear the exact same when rendered. Is there a function maybe different from leafletProxy() to get the actual htmlwidget object?

library(shiny)
library(leaflet)

m1 <- leaflet() %>% addTiles()

shinyApp(
  ui = fluidPage(
    textOutput("test"),
    br(),
    leafletOutput("mymap")
  ),
  server = function(input, output, session) {
    output$mymap <- renderLeaflet({
      leaflet() %>% addTiles()
    })
    output$test <- renderText({
      sprintf("Are the two maps the same?: %s", 
              identical(m1, leafletProxy("mymap")))
    })
  }
)

Reasoning: The reason that I would like the actual rendered object is that I have a Shiny application where the map is updated multiple times using leafletProxy() and then it needs to be downloaded to an HTML file. The problem is saveWidget, webshot, mapshot and other functions need the actual map object, not the proxy version in order to save. This question has been posted multiple times in a few different ways, but the only viable solution is to create two maps side-by-side: one that's updated via leafletProxy() and another that's built directly on top of the call to leaflet(). I would rather not maintain two different maps.

Potential Duplicate Questions

  • Saving LeafletProxy results of user-input in Shiny R
  • Saving leaflet maps in R shiny
  • https://github.com/r-spatial/mapview/issues/77
  • https://github.com/ramnathv/htmlwidgets/issues/271
  • https://community.rstudio.com/t/solved-error-when-using-mapshot-with-shiny-leaflet/6765

Disclaimer I have cross-posted this question as an issue to the manipulateWidget package since it seems like the most promising area where already rendered objects in Shiny can be retrieved. https://github.com/rte-antares-rpackage/manipulateWidget/issues/59

来源:https://stackoverflow.com/questions/51334762/return-a-rendered-leaflet-map-from-leafletproxy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!