0

I'm using the leaflet and shiny packages to create interactive maps in a web browser (Chrome). When updating leaflet from version 1.1.0 to version 2.0.0 some choropleth maps stopped showing correctly: most if not all of the polygons failed to show. What makes it more bizarre is that R is not showing any errors or warnings.

What I expected

Choropleth map as I expected it

What I got

Choropleth not showing correctly

I'm quite certain the error has to do with the new leaflet version, as this program was running fine before the update and has not been altered since (except for a small fix, related to this issue).

Session info

R version 3.4.3 (2017-11-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.3 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] sp_1.2-7

loaded via a namespace (and not attached):
[1] compiler_3.4.3  tools_3.4.3     grid_3.4.3      lattice_0.20-35
MLavoie
  • 9,671
  • 41
  • 36
  • 56
Willem
  • 976
  • 9
  • 24

1 Answers1

0

I managed to solve the problem by eliminating all mentions of dashArray in the addPolygons function.

In the code below I eliminated the line dashArray = "",

leafletProxy("map") %>%
      addPolygons(
        data = sp,
        stroke = FALSE,
        fillOpacity = 0.9,
        smoothFactor = 0.5,
        color = colors,
        group = "Analysis",
        highlight = highlightOptions(
          weight = 10,
          color = "#666",
          dashArray = "",
          fillOpacity = 1,
          bringToFront = TRUE,
          stroke = FALSE
        ),
        label = label
      ) %>%
      addLegend(
        position = "bottomright",
        pal = colorPalette,
        values = colorValues,
        layerId = "legendColors",
        title = legendTitle
      )

Somehow this dashArray causes an error in javascript (?). Anyway when looking at the console in my browser I got the following error, which was the clue to solve the issue.

dashArray error

I hope this helps others to solve this very cryptic error!

Willem
  • 976
  • 9
  • 24