I want to add a feature for users to export a map, produced by Tmap, in Shiny. I understand that tmap converts the map to leaflet but it doesn't work with mapview::mapshot as many answers give for saving Leaflet maps in Shiny.
None of the following work:
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)
}
)