【发布时间】:2020-10-31 07:38:15
【问题描述】:
我想添加一个功能,供用户在 Shiny 中导出地图,由 Tmap 制作。我知道 tmap 将地图转换为传单,但它不适用于 mapview::mapshot,因为许多答案都给出了在 Shiny 中保存 Leaflet 地图的答案。
以下都不起作用:
map_expr <- reactive({
tm_shape(water1) +
tm_fill(col = "darkblue") +
tm_shape(county_outlines) +
tm_borders(col = "black") +
tm_shape(herd_summary) +
tm_symbols(col = "green", size = "REACTORS", scale = 0.15, alpha = 0.7) +
tm_shape(water1) +
tm_fill(col = "darkblue")
})
observe({
output$map <- renderTmap({
map_expr()
})
})
output$downloadData <- downloadHandler(
filename = "test.png",
content = function(file) {
# mapshot(map_expr(), file = file, cliprect = "viewport")
# tmap_save(map_expr(), file = file)
tmapProxy("map", session, {}) %>%
mapview::mapshot(file = file)
}
)
【问题讨论】:
-
我也遇到了同样的问题 - 您找到解决方案了吗?
-
很遗憾没有;我最终做的是使用 renderPlot 和 plotOutput,它们使用静态图(如果熟悉 tmap,则为 tmap_mode("plot")),然后在下载处理程序中使用 tmap_save。这意味着绘图是非交互式的,但在我的例子中,用户能够保存地图比拥有交互式功能更重要。
-
再看一遍后,我想我已经成功了,我会添加它作为答案