Skip to content

save_map() does not set widget width/height properties correctly before saving/capture #192

@danielvartan

Description

@danielvartan

Summary

mapgl::save_map() does not consistently set the widget width and height properties correctly before rendering/capture. This can produce images with dimensions that do not match the values passed to save_map(width = ..., height = ...).

Reproducible Example

library(geobr)
library(mapgl)

brazil_shape <- read_country()

map <- 
  brazil_shape |>
  maplibre(
    width = "1000px",
    height = "1000px",
    bounds = _
  ) |>
  add_fill_layer(
    id = "fill",
    source = brazil_shape,
    fill_color = "blue"
  ) |>
  add_navigation_control()

map |>
  save_map(
    width = 1000,
    height = 500,
    hide_controls = TRUE
  )

Result:

Image

Expected behavior

Output image dimensions should match the save_map() arguments.

Actual behavior

Exported dimensions can be inconsistent because widget width/height are not correctly set before rendering.

Environment

devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.5.3 (2026-03-11)
#>  os       Arch Linux
#>  system   x86_64, linux-gnu
#>  ui       X11
#>  language en
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       America/Sao_Paulo
#>  date     2026-04-05
#>  pandoc   3.6.3 @ /usr/share/positron/resources/app/quarto/bin/tools/x86_64/ (via rmarkdown)
#>  quarto   1.8.27 @ /opt/quarto/bin/quarto
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cachem        1.1.0   2024-05-16 [1] CRAN (R 4.5.1)
#>  cli           3.6.5   2025-04-23 [1] CRAN (R 4.5.2)
#>  devtools      2.4.6   2025-10-03 [1] CRAN (R 4.5.2)
#>  digest        0.6.39  2025-11-19 [1] CRAN (R 4.5.2)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.5.1)
#>  evaluate      1.0.5   2025-08-27 [1] CRAN (R 4.5.1)
#>  fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.5.1)
#>  fs            1.6.6   2025-04-12 [1] CRAN (R 4.5.2)
#>  glue          1.8.0   2024-09-30 [1] CRAN (R 4.5.1)
#>  htmltools     0.5.9   2025-12-04 [1] CRAN (R 4.5.2)
#>  knitr         1.51    2025-12-20 [1] CRAN (R 4.5.2)
#>  lifecycle     1.0.5   2026-01-08 [1] CRAN (R 4.5.2)
#>  magrittr      2.0.4   2025-09-12 [1] CRAN (R 4.5.2)
#>  memoise       2.0.1   2021-11-26 [1] CRAN (R 4.5.1)
#>  otel          0.2.0   2025-08-29 [1] CRAN (R 4.5.2)
#>  pkgbuild      1.4.8   2025-05-26 [1] CRAN (R 4.5.1)
#>  pkgload       1.5.0   2026-02-03 [1] CRAN (R 4.5.2)
#>  purrr         1.2.1   2026-01-09 [1] CRAN (R 4.5.2)
#>  R6            2.6.1   2025-02-15 [1] CRAN (R 4.5.1)
#>  remotes       2.5.0   2024-03-17 [1] CRAN (R 4.5.2)
#>  reprex        2.1.1   2024-07-06 [1] CRAN (R 4.5.1)
#>  rlang         1.1.7   2026-01-09 [1] CRAN (R 4.5.2)
#>  rmarkdown     2.30    2025-09-28 [1] CRAN (R 4.5.2)
#>  sessioninfo   1.2.3   2025-02-05 [1] CRAN (R 4.5.1)
#>  usethis       3.2.1   2025-09-06 [1] CRAN (R 4.5.2)
#>  vctrs         0.7.1   2026-01-23 [1] CRAN (R 4.5.2)
#>  withr         3.0.2   2024-10-28 [1] CRAN (R 4.5.2)
#>  xfun          0.56    2026-01-18 [1] CRAN (R 4.5.2)
#>  yaml          2.3.12  2025-12-10 [1] CRAN (R 4.5.2)
#> 
#>  [1] /home/danielvartan/R/x86_64-pc-linux-gnu-library/4.5
#>  [2] /usr/lib/R/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Created on 2026-04-05 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions