r-spatial / leafpop

Include Tables, Images and Graphs in Leaflet Popups
Other
113 stars 15 forks source link

All Popup graphs are repeatedly stacked for each spatial point #22

Closed maxime-soma closed 3 years ago

maxime-soma commented 3 years ago

Hi, I have an issue with attaching a given popup graph to its coresponding point. I have a code which works perfectly on a previous computer, and this issue arises on a new one, despite the code is exactly the same. Packages versions are also the same. I tried with the demo code and I have the same issue.

library(mapview)
library(leaflet)
library(leafpop)
library(lattice)
library(sp)

data(meuse)
coordinates(meuse) <- ~x+y
proj4string(meuse) <- CRS("+init=epsg:28992")

p <- xyplot(copper ~ cadmium, data = meuse@data, col = "grey", pch = 20, cex = 2)
p <- mget(rep("p", length(meuse)))

clr <- rep("grey", length(meuse))
p <- lapply(1:length(p), function(i) {
  clr[i] <- "red"
  update(p[[i]], col = clr)
})

mapview(meuse,
        zcol = "cadmium",
        popup = popupGraph(p))

And here is the resulting graph: image

All graphs for the dataset are stacked in each popup, and I really don't understand why. Meaning in each point I click, I can scroll down all the 155 graphs, which is rather unpractical.

Thank you very much for your help, Maxime

maxime-soma commented 3 years ago

I tried this solution (https://github.com/r-spatial/mapview/issues/369#issuecomment-803554455): remotes::install_github("r-spatial/leafem")

but now there is no popup graph at all: image

tim-salabim commented 3 years ago

Thanks for spotting this! Should now work as expected if used from mapview. In case someone wants to do this via leafem::addFgb() there is now a note printed to the browser console that this is currently not possible....

Can you please re-try and confirm whether this now works as expected for you?

maxime-soma commented 3 years ago

Thanks for your help. Unfortunately, I still have the same issue (even with the 'meuse' demo code). I updated the package with

tim-salabim commented 3 years ago

Can you please provide your sessionInfo()?

maxime-soma commented 3 years ago

Sorry my last response was truncated. I updated packages with

devtools::install_github("r-spatial/mapview")
devtools::install_github("r-spatial/leafpop")

My sessionInfo() :

R version 4.0.5 (2021-03-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default
locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C                   LC_TIME=French_France.1252    

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

other attached packages:
[1] sp_1.4-5        lattice_0.20-41 leafpop_0.0.8   leafem_0.1.3    leaflet_2.0.4.1 mapview_2.9.9 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6              svglite_2.0.0           leaflet.providers_1.9.0 png_0.1-7              
 [5] prettyunits_1.1.1       class_7.3-18            ps_1.6.0                rprojroot_2.0.2        
 [9] digest_0.6.27           utf8_1.2.1              R6_2.5.0                stats4_4.0.5           
[13] e1071_1.7-6             ggplot2_3.3.3           pillar_1.6.0            rlang_0.4.11           
[17] uuid_0.1-4              data.table_1.14.0       callr_3.7.0             raster_3.4-5           
[21] desc_1.3.0              devtools_2.4.1          rgdal_1.5-23            webshot_0.5.2          
[25] htmlwidgets_1.5.3       munsell_0.5.0           tinytex_0.31            proxy_0.4-25           
[29] compiler_4.0.5          xfun_0.22               pkgconfig_2.0.3         systemfonts_1.0.2      
[33] base64enc_0.1-3         pkgbuild_1.2.0          htmltools_0.5.1.1       tidyselect_1.1.1       
[37] tibble_3.1.1            codetools_0.2-18        fansi_0.4.2             crayon_1.4.1           
[41] dplyr_1.0.5             withr_2.4.2             sf_0.9-8                ModelMetrics_1.2.2.2   
[45] grid_4.0.5              jsonlite_1.7.2          satellite_1.0.2         gtable_0.3.0           
[49] lifecycle_1.0.0         DBI_1.1.1               magrittr_2.0.1          units_0.7-1            
[53] scales_1.1.1            KernSmooth_2.23-18      cli_2.5.0               cachem_1.0.4           
[57] farver_2.1.0            fs_1.5.0                remotes_2.3.0           testthat_3.0.2         
[61] ellipsis_0.3.1          brew_1.0-6              generics_0.1.0          vctrs_0.3.7            
[65] tools_4.0.5             glue_1.4.2              purrr_0.3.4             crosstalk_1.1.1        
[69] yaml_2.2.1              processx_3.5.2          pkgload_1.2.1           fastmap_1.1.0          
[73] colorspace_2.0-0        terra_1.1-17            sessioninfo_1.1.1       classInt_0.4-3         
[77] memoise_2.0.0           usethis_2.0.1
tim-salabim commented 3 years ago

Can you please also remotes::install_github("r-spatial/leafem") to see if that solves the problem?

maxime-soma commented 3 years ago

Great, updating leafem almost solved the problem. To note, when I used remotes I did not installed last versions. I had to use devtools::install_github("r-spatial/leafem") to get them.

It works fine with the 'meuse' demo code. Yet, in my own code, I would like to control the size of the popup windows. I had no issue on the previous computer, but now, despite the size of the windows is larger, the graph does not fully occupy the available "space" and the displayed graph is splitted. Do I miss an argument ?

mapview(is2, cex= 10, zcol="Hmax_m" , at = seq(Hmin, Hmax, pas_leg), legend = TRUE, label="", layer.name="is2 Hmax (m)", popup= leafpop::popupGraph(plot,width = 600,height = 300))) image

tim-salabim commented 3 years ago

This should work now when you re-install leafem

maxime-soma commented 3 years ago

Great, everything works fine now. Thank you for your help and these amazing packages !

tim-salabim commented 3 years ago

No problem. Thanks for using them! :-)