r-spatial / mapview

Interactive viewing of spatial data in R
https://r-spatial.github.io/mapview/
GNU General Public License v3.0
519 stars 90 forks source link

mapshot drops legend on mapview of stars object with factors #423

Open przell opened 2 years ago

przell commented 2 years ago

Hi @tim-salabim, thanks for supporting stars objects with factors now in mapview! That's an awesome feature! I am trying to generate a mapshot from a mapview object that is showing a stars object with factors. Mapshot drops the legend. Here an example:

lc <- read_stars(system.file('tif/lc.tif',package='stars'))
tst_mv = mapview(lc)
tst_mv # legend there
mapshot(x = tst_mv, file = "test.png") # legend gone
Session Info ```r > sessionInfo() R version 4.0.5 (2021-03-31) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.4 LTS Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1 locale: [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8 LC_COLLATE=C.UTF-8 [5] LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8 LC_PAPER=C.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] mapview_2.11.0 stars_0.5-5 sf_1.0-7 abind_1.4-5 loaded via a namespace (and not attached): [1] tidyselect_1.1.1 terra_1.5-17 purrr_0.3.4 lattice_0.20-41 [5] colorspace_2.0-3 vctrs_0.4.0 generics_0.1.2 leaflet.providers_1.9.0 [9] htmltools_0.5.2 stats4_4.0.5 yaml_2.3.5 base64enc_0.1-3 [13] utf8_1.2.2 rlang_1.0.2 e1071_1.7-9 pillar_1.7.0 [17] glue_1.6.2 DBI_1.1.2 sp_1.4-6 lifecycle_1.0.1 [21] munsell_0.5.0 raster_3.5-15 htmlwidgets_1.5.4 codetools_0.2-18 [25] callr_3.7.0 fastmap_1.1.0 ps_1.6.0 crosstalk_1.2.0 [29] parallel_4.0.5 class_7.3-18 fansi_1.0.3 leafem_0.1.8.9000 [33] Rcpp_1.0.8.3 KernSmooth_2.23-18 scales_1.1.1 classInt_0.4-3 [37] satellite_1.0.2 lwgeom_0.2-8 leaflet_2.0.4.9000 webshot_0.5.2 [41] jsonlite_1.8.0 farver_2.1.0 png_0.1-7 digest_0.6.29 [45] processx_3.5.3 dplyr_1.0.7 grid_4.0.5 cli_3.2.0 [49] tools_4.0.5 magrittr_2.0.3 proxy_0.4-26 tibble_3.1.6 [53] crayon_1.5.1 pkgconfig_2.0.3 ellipsis_0.3.2 assertthat_0.2.1 [57] R6_2.5.1 units_0.8-0 compiler_4.0.5 ```
tim-salabim commented 2 years ago

Not sure what's happening... I'll look into it

tim-salabim commented 2 years ago

@przell with https://github.com/r-spatial/mapview/tree/429-update-to-webshot2 this seems to work. You can install that branch with

remotes::install_github("r-spatial/mapview@429-update-to-webshot2")

and then

library(mapview)
library(stars)

# Sys.setenv("CHROMOTE_CHROME" = "/usr/bin/brave-browser") # just in case chromote cannot find a suitable browser

lc <- read_stars(system.file('tif/lc.tif',package='stars'))
tst_mv = mapview(lc)
tst_mv # legend there
mapshot(x = tst_mv, file = "/home/tim/Downloads/test.png") # legend gone

produces test

Please let me know if this works for ou too.

mfidino commented 2 years ago

This fixed my version of this issue.

R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

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

other attached packages:
[1] stringr_1.4.0       bdc_1.1.1          
[3] igraph_1.3.1        magick_2.7.3       
[5] leaflet_2.1.1       mapview_2.11.0.9001
[7] data.table_1.14.2   sf_1.0-7           

loaded via a namespace (and not attached):
 [1] fs_1.5.2                 satellite_1.0.4         
 [3] oai_0.3.2                progress_1.2.2          
 [5] httr_1.4.3               rprojroot_2.0.3         
 [7] rgbif_3.7.2              tools_4.2.0             
 [9] utf8_1.2.2               rgdal_1.5-32            
[11] R6_2.5.1                 DT_0.23                 
[13] KernSmooth_2.23-20       rgeos_0.5-9             
[15] DBI_1.1.2                lazyeval_0.2.2          
[17] colorspace_2.0-3         raster_3.5-15           
[19] sp_1.4-7                 prettyunits_1.1.1       
[21] tidyselect_1.1.2         processx_3.5.3          
[23] curl_4.3.2               compiler_4.2.0          
[25] leafem_0.2.0             cli_3.3.0               
[27] xml2_1.3.3               stringfish_0.15.7       
[29] scales_1.2.0             classInt_0.4-3          
[31] readr_2.1.2              askpass_1.1             
[33] proxy_0.4-26             digest_0.6.29           
[35] contentid_0.0.15         base64enc_0.1-3         
[37] pkgconfig_2.0.3          htmltools_0.5.2         
[39] dbplyr_2.2.0             fastmap_1.1.0           
[41] htmlwidgets_1.5.4        rlang_1.0.2             
[43] generics_0.1.2           RApiSerialize_0.1.0     
[45] jsonlite_1.8.0           crosstalk_1.2.0         
[47] dplyr_1.0.9              magrittr_2.0.3          
[49] geosphere_1.5-14         Rcpp_1.0.8.3            
[51] munsell_0.5.0            fansi_1.0.3             
[53] CoordinateCleaner_2.0-20 rgnparser_0.2.0         
[55] lifecycle_1.0.1          terra_1.5-21            
[57] stringi_1.7.6            whisker_0.4             
[59] plyr_1.8.7               grid_4.2.0              
[61] parallel_4.2.0           promises_1.2.0.1        
[63] crayon_1.5.1             lattice_0.20-45         
[65] conditionz_0.1.0         chromote_0.1.0          
[67] hms_1.1.1                sys_3.4                 
[69] ps_1.7.0                 pillar_1.7.0            
[71] uuid_1.1-0               codetools_0.2-18        
[73] stats4_4.2.0             glue_1.6.2              
[75] arkdb_0.0.15             RcppParallel_5.1.5      
[77] png_0.1-7                vctrs_0.4.1             
[79] tzdb_0.3.0               foreach_1.5.2           
[81] openssl_2.0.2            gtable_0.3.0            
[83] purrr_0.3.4              webshot2_0.1.0          
[85] qs_0.25.3                assertthat_0.2.1        
[87] ggplot2_3.3.6            e1071_1.7-9             
[89] rnaturalearth_0.1.0      taxadb_0.1.5            
[91] later_1.3.0              class_7.3-20            
[93] tibble_3.1.7             iterators_1.0.14        
[95] websocket_1.4.1          units_0.8-0             
[97] ellipsis_0.3.2           here_1.0.1
przell commented 2 years ago

Can also confirm that it's working after installing remotes::install_github("r-spatial/mapview@429-update-to-webshot2")

tim-salabim commented 2 years ago

Thanks!

manomuthus commented 1 year ago

Hi, I have the same issue where mapview (version 2.11.0) drops the legend when I save it as a png. I don't think this branch exists anymore. How can I resolve this issue? Thanks.

tim-salabim commented 1 year ago

I think it should work if you

remotes::install_github("r-spatial/mapview")