Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmap code fails on 'Run code' but works on tutorial load or 'Start Over' #484

Closed
andysouth opened this issue Feb 2, 2021 · 2 comments · Fixed by #486
Closed

tmap code fails on 'Run code' but works on tutorial load or 'Start Over' #484

andysouth opened this issue Feb 2, 2021 · 2 comments · Fixed by #486

Comments

@andysouth
Copy link

System details

Output of sessioninfo::session_info()():

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 10240)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

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

other attached packages:
[1] learnr_0.10.1.9008    afrilearnr_0.0.0.9000 devtools_2.3.2        usethis_2.0.0        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6           later_1.1.0.1        compiler_4.0.3       prettyunits_1.1.1   
 [5] remotes_2.2.0        tools_4.0.3          testthat_3.0.0       digest_0.6.27       
 [9] pkgbuild_1.1.0       pkgload_1.1.0        jsonlite_1.7.2       memoise_1.1.0       
[13] evaluate_0.14        lifecycle_0.2.0      rlang_0.4.10         shiny_1.6.0         
[17] cli_2.2.0            rstudioapi_0.13      curl_4.3             yaml_2.2.1          
[21] xfun_0.20            fastmap_1.1.0        withr_2.4.1          knitr_1.31          
[25] htmlwidgets_1.5.3    desc_1.2.0           fs_1.5.0             rprojroot_2.0.2     
[29] glue_1.4.2           R6_2.5.0             processx_3.4.4       fansi_0.4.1         
[33] rmarkdown_2.6        sessioninfo_1.1.1    callr_3.5.1          purrr_0.3.4         
[37] magrittr_2.0.1       promises_1.1.1       ps_1.4.0             ellipsis_0.3.1      
[41] htmltools_0.5.1.9000 assertthat_0.2.1     xtable_1.8-4         mime_0.9            
[45] renv_0.12.5          httpuv_1.5.5         markdown_1.1         crayon_1.4.0 

Example application or steps to reproduce the problem

https://andysouth.shinyapps.io/test-tmap-view/
https://github.com/afrimapr/afrilearnr/blob/main/inst/tutorials/test-tmap-view/test-tmap-view.Rmd

library(learnr)
knitr::opts_chunk$set(echo = FALSE)

library(tmap)
data("World")
tmap_mode("view")
tm_shape(World) +
    tm_polygons("HPI")

Describe the problem in detail

The chunk above - the Hello World ! example from tmap, with tmap_mode(“view”) added, works when the tutorial is loaded, or on 'Start Over' or when run from console, but fails (with $ operator is invalid for atomic vectors) when ‘Run Code’ is pressed

@gadenbuie
Copy link
Member

gadenbuie commented Feb 3, 2021

Thanks for the report @andysouth. The issue was caused by a call like

htmltools::tags$head(
  htmltools::HTML("<style>.leaflet-container {background: #FFFFFF;}</style>")
)

somewhere in the process that creates the leaflet map. learnr doesn't allow users to add arbitrary HTML dependencies because we don't want code run by the user to disrupt the appearance or functionality of the running tutorial. As a result, the dependency created by the code above gets removed from the HTML output returned by the user's exercise code.

If you want to match the default tmap appearance, you can include such a statement in an R chunk in your tutorial.

This issue should be fixed when #486 merges, please report back if this does not resolve your problem!

@andysouth
Copy link
Author

Many thanks @gadenbuie for the prompt response.

Yes, this works for me now. See in action here : https://andysouth.shinyapps.io/intro-to-spatial-r/#section-interactive-maps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants