This function exports a map widget as an image file using webshot2 or mapview. Works in non-Shiny contexts like RMarkdown, scripts, or interactive sessions.
Arguments
- map
A map object created by
map().- filepath
The file path to save the image (including extension).
- width
The width of the image in pixels. Default is 800.
- height
The height of the image in pixels. Default is 600.
- delay
The delay in seconds before capturing. Default is 2.
- zoom
The zoom factor for the capture. Default is 1.
- ...
Additional arguments passed to
webshot2::webshot()ormapview::mapshot().
Examples
# \donttest{
if (check_chrome_available()) {
# Load library
library(sf)
data <- data.frame(lon = 174.8210, lat = -41.3096) |>
sf::st_as_sf(coords = c("lon", "lat"), crs = 4326)
# Create and export a map
my_map <- map() |>
add_circle_layer("epi_circle", source = data)
export_map_image(my_map, file.path(tempdir(), "my_map.png"), width = 1200, height = 800)
}
#> file:///C:/Users/KielHards/AppData/Local/Temp/Rtmpi4ySix/fileb78522a1e13.html screenshot completed
#> Map exported to: C:\Users\KIELHA~1\AppData\Local\Temp\Rtmpi4ySix/my_map.png
# }
