mapview icon indicating copy to clipboard operation
mapview copied to clipboard

Broken RMarkdown html TOC with leaflet::addMeasure and DT::datatable

Open markolipka opened this issue 4 years ago • 3 comments

Hi Tim,

I recently stumbled upon a strange error that I cannot really find a cause for. It is probably not even a problem with the mapview package but I hope that you might provide a hint how to work around this bug.

Under very specific conditions, the table of content of an RMarkdown html document is unfavorably altered. When I add a leaflet::addMeasure() to a mapview()-map and call a DT::datatable() afterwards, the floating table of contents in an RMarkdown-Document has two additional entries "Measure distances and areas" while the following subchapter disappears from the TOC.

Here a reproducible example that produces the unwanted behaviour both under R 3.6.1 on a Windows machine and R 4.0.2 on a Mac. Note, that I had to "escape" the code chunk closing tripple-GraveAccent lines ("!```") to provide a RMarkdown codeblock here:

---
title: "ReprEx: mapview, addMeasure, datatable"
output:
  html_document:
    toc: yes
    toc_float:
      collapsed: no
---

# Chapter 1

```{r}
library(mapview)
library(leaflet)
library(DT)
addMeasure(mapview(breweries)@map)
!```

```{r, eval = TRUE}
datatable(data.frame(a = 1))
!```

## subchapter that disappears in TOC

## visible subchapter

image

Feel free to close this if the problem is unrelated to mapview. Thanks for the amazing package!

Two sessionInfos:

sessionInfo()
## R version 4.0.2 (2020-06-22)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS  10.16
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] DT_0.17         leaflet_2.0.4.1 mapview_2.9.8  
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.6              svglite_2.0.0           lattice_0.20-41        
##  [4] png_0.1-7               class_7.3-18            leaflet.providers_1.9.0
##  [7] assertthat_0.2.1        digest_0.6.27           utf8_1.2.1             
## [10] R6_2.5.0                leafpop_0.0.6           stats4_4.0.2           
## [13] evaluate_0.14           e1071_1.7-6             pillar_1.5.1           
## [16] rlang_0.4.10            uuid_0.1-4              raster_3.4-5           
## [19] jquerylib_0.1.3         rmarkdown_2.7           webshot_0.5.2          
## [22] stringr_1.4.0           htmlwidgets_1.5.3       munsell_0.5.0          
## [25] proxy_0.4-25            compiler_4.0.2          xfun_0.22              
## [28] pkgconfig_2.0.3         systemfonts_1.0.1       base64enc_0.1-3        
## [31] htmltools_0.5.1.1       tidyselect_1.1.0        tibble_3.1.0           
## [34] codetools_0.2-18        fansi_0.4.2             crayon_1.4.1           
## [37] dplyr_1.0.4             sf_0.9-8                grid_4.0.2             
## [40] jsonlite_1.7.2          satellite_1.0.2         lifecycle_1.0.0        
## [43] DBI_1.1.1               magrittr_2.0.1          units_0.7-1            
## [46] scales_1.1.1            KernSmooth_2.23-18      stringi_1.5.3          
## [49] sp_1.4-5                bslib_0.2.4             ellipsis_0.3.1         
## [52] brew_1.0-6              generics_0.1.0          vctrs_0.3.6            
## [55] RColorBrewer_1.1-2      tools_4.0.2             leafem_0.1.4           
## [58] glue_1.4.2              purrr_0.3.4             crosstalk_1.1.1        
## [61] yaml_2.2.1              colorspace_2.0-0        classInt_0.4-3         
## [64] knitr_1.31              sass_0.3.1
sessionInfo()
## R version 3.6.1 (2019-07-05)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18363)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
## [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
## [5] LC_TIME=German_Germany.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] DT_0.17         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           lattice_0.20-41        
##  [4] png_0.1-7               class_7.3-18            leaflet.providers_1.9.0
##  [7] assertthat_0.2.1        digest_0.6.27           utf8_1.2.1             
## [10] R6_2.5.0                leafpop_0.0.6           stats4_3.6.1           
## [13] evaluate_0.14           e1071_1.7-6             pillar_1.5.1           
## [16] rlang_0.4.10            uuid_0.1-4              raster_3.4-5           
## [19] jquerylib_0.1.3         rmarkdown_2.7           webshot_0.5.2          
## [22] stringr_1.4.0           htmlwidgets_1.5.3       munsell_0.5.0          
## [25] proxy_0.4-25            compiler_3.6.1          xfun_0.22              
## [28] pkgconfig_2.0.3         systemfonts_1.0.1       base64enc_0.1-3        
## [31] htmltools_0.5.1.1       tidyselect_1.1.0        tibble_3.1.0           
## [34] codetools_0.2-18        fansi_0.4.2             crayon_1.4.1           
## [37] dplyr_1.0.5             sf_0.9-8                grid_3.6.1             
## [40] jsonlite_1.7.2          satellite_1.0.2         lifecycle_1.0.0        
## [43] DBI_1.1.1               magrittr_2.0.1          units_0.7-1            
## [46] scales_1.1.1            KernSmooth_2.23-18      stringi_1.5.3          
## [49] sp_1.4-5                bslib_0.2.4             ellipsis_0.3.1         
## [52] brew_1.0-6              generics_0.1.0          vctrs_0.3.7            
## [55] RColorBrewer_1.1-2      tools_3.6.1             leafem_0.1.3           
## [58] glue_1.4.2              purrr_0.3.4             crosstalk_1.1.1        
## [61] yaml_2.2.1              colorspace_2.0-0        classInt_0.4-3         
## [64] knitr_1.31              sass_0.3.1

markolipka avatar Apr 13 '21 13:04 markolipka

That seems like some CSS problem. Does this only happen when the map is created with mapview? Or does it also happen with a native leaflet map?

tim-salabim avatar Apr 13 '21 14:04 tim-salabim

Hey, thanks for the super quick response!

This also happens with leaflet: Screenshot 2021-04-13 at 16 40 47

Sorry, I could have thought of trying that myself.

So I guess I should file this issue somewhere else? leaflet or rather rmarkdown? I don't have the slightest understanding of CSS, unfortunately.

markolipka avatar Apr 13 '21 14:04 markolipka

Yes, that means it's not a mapview issue. I don't know where this originates so can only guess. Seems specific to the addMeasure plugin, so maybe leaflet is a good place to start. In any case they're hey're both RStudio packages...

tim-salabim avatar Apr 13 '21 14:04 tim-salabim