r-tmap / tmap

R package for thematic maps
https://r-tmap.github.io/tmap
GNU General Public License v3.0
864 stars 121 forks source link

CartoDB tiles not showing in RStudio (?) #201

Closed mtennekes closed 6 years ago

mtennekes commented 6 years ago

Hi all,

There seems to be an issue with the CartoDB tile servers and RStudio: the tiles are seem to be displayed in an external browser, but not in the RStudio viewer pane, nor in a Shiny app (as @Robinlovelace 's live demo during his eRum2018 talk on wednesday pointed out).

Could you please do me a little favor (@Nowosad @jannes-m @edwindj @Egge-Jan @joelgombin @tim-salabim) and check if you see tiles in RStudio? You can just run this code:

tmap_mode("view")
qtm()

Version 2.0 will be released within a few weeks, and I'm considering changing the default tile server if this problem cannot be resolved.

tim-salabim commented 6 years ago

@mtennekes see this issue on leaflet https://github.com/rstudio/leaflet/issues/546. It is a known RStudio problem which should be resolved with the next major release (1.2.x). You can try a daily build from https://dailies.rstudio.com/ and the issue should no longer exist.

Robinlovelace commented 6 years ago

I can reproduce this issue on my computer. No basemaps are working for me, e.g.:

qtm(world) +
  tm_view(basemaps = leaflet::providers$Thunderforest.OpenCycleMap)

Interestingly it still fails when I pass the output to tmap_leaflet() but when I do that inside a reprex it works as illustrated below. Interestingly the command above does not render a basemap in the browser either...

Reprex showing it works in a reprex at least (test: try running these - only the commands starting leaflet() work in RStudio for me:

library(tmap)
library(magrittr)
library(spData)
tmap_mode("view")
#> tmap mode set to interactive viewing
qtm()
#> Error in knit_print(x = structure(list(x = structure(list(options = structure(list(: could not find function "knit_print"
qtm(world) + tm_view(basemaps = leaflet::providers$Thunderforest.OpenCycleMap) %>% 
  tmap_leaflet()
#> Linking to GEOS 3.5.1, GDAL 2.2.2, proj.4 4.9.2

qtm(world) + tm_view(basemaps = c(leaflet::providers$OpenStreetMap, leaflet::providers$OpenStreetMap.Mapnik)) %>% 
  tmap_leaflet()


library(leaflet)
leaflet() %>% addTiles()

leaflet() %>% addProviderTiles(leaflet::providers$CartoDB.Positron)

Session info ``` r devtools::session_info() #> Session info ------------------------------------------------------------- #> setting value #> version R version 3.4.4 (2018-03-15) #> system x86_64, linux-gnu #> ui X11 #> language en_GB:en #> collate en_GB.UTF-8 #> tz Europe/London #> date 2018-05-18 #> Packages ----------------------------------------------------------------- #> package * version date source #> backports 1.1.2 2017-12-13 CRAN (R 3.4.3) #> base * 3.4.4 2018-03-16 local #> base64enc 0.1-3 2015-07-28 cran (@0.1-3) #> bitops 1.0-6 2013-08-17 CRAN (R 3.4.1) #> boot 1.3-20 2017-07-30 CRAN (R 3.4.1) #> class 7.3-14 2015-08-30 CRAN (R 3.4.0) #> classInt 0.2-3 2018-04-16 cran (@0.2-3) #> coda 0.19-1 2016-12-08 cran (@0.19-1) #> codetools 0.2-15 2016-10-05 CRAN (R 3.3.1) #> colorspace 1.3-2 2016-12-14 CRAN (R 3.4.1) #> compiler 3.4.4 2018-03-16 local #> crosstalk 1.0.0 2016-12-21 cran (@1.0.0) #> curl 3.2 2018-03-28 CRAN (R 3.4.4) #> datasets * 3.4.4 2018-03-16 local #> DBI 1.0.0 2018-05-02 cran (@1.0.0) #> deldir 0.1-15 2018-04-01 CRAN (R 3.4.4) #> devtools 1.13.5 2018-02-18 CRAN (R 3.4.4) #> dichromat 2.0-0 2013-01-24 CRAN (R 3.3.2) #> digest 0.6.15 2018-01-28 CRAN (R 3.4.3) #> e1071 1.6-8 2017-02-02 cran (@1.6-8) #> evaluate 0.10.1 2017-06-24 CRAN (R 3.4.1) #> expm 0.999-2 2017-03-29 cran (@0.999-2) #> foreach 1.4.4 2017-12-12 CRAN (R 3.4.3) #> formatR 1.5 2017-04-25 CRAN (R 3.4.1) #> gdalUtils 2.0.1.14 2018-04-23 CRAN (R 3.4.4) #> gdata 2.18.0 2017-06-06 cran (@2.18.0) #> geojsonlint 0.2.0 2016-11-03 cran (@0.2.0) #> geosphere 1.5-7 2017-11-05 CRAN (R 3.4.2) #> gmodels 2.16.2 2015-07-22 cran (@2.16.2) #> graphics * 3.4.4 2018-03-16 local #> grDevices * 3.4.4 2018-03-16 local #> grid 3.4.4 2018-03-16 local #> gtools 3.5.0 2015-05-29 cran (@3.5.0) #> htmltools 0.3.6 2017-04-28 cran (@0.3.6) #> htmlwidgets 1.2 2018-04-19 CRAN (R 3.4.4) #> httpuv 1.4.3 2018-05-10 CRAN (R 3.4.4) #> httr 1.3.1 2017-08-20 cran (@1.3.1) #> iterators 1.0.9 2017-12-12 CRAN (R 3.4.3) #> jsonlite 1.5 2017-06-01 cran (@1.5) #> jsonvalidate 1.0.0 2016-06-13 cran (@1.0.0) #> KernSmooth 2.23-15 2015-06-29 CRAN (R 3.4.0) #> knitr 1.20 2018-02-20 cran (@1.20) #> later 0.7.2 2018-05-01 CRAN (R 3.4.4) #> lattice 0.20-35 2017-03-25 CRAN (R 3.3.3) #> leaflet * 2.0.0 2018-04-20 cran (@2.0.0) #> LearnBayes 2.15.1 2018-03-18 CRAN (R 3.4.4) #> lwgeom 0.1-5 2018-03-20 Github (r-spatial/lwgeom@389090c) #> magrittr * 1.5 2014-11-22 CRAN (R 3.3.2) #> mapview 2.4.0 2018-04-28 CRAN (R 3.4.4) #> MASS 7.3-50 2018-04-30 CRAN (R 3.4.4) #> Matrix 1.2-14 2018-04-09 CRAN (R 3.4.4) #> memoise 1.1.0 2017-04-21 CRAN (R 3.4.1) #> methods * 3.4.4 2018-03-16 local #> mime 0.5 2016-07-07 CRAN (R 3.3.2) #> munsell 0.4.3 2016-02-13 CRAN (R 3.3.2) #> nlme 3.1-137 2018-04-07 CRAN (R 3.4.4) #> osmar 1.1-7 2013-11-21 cran (@1.1-7) #> plyr 1.8.4 2016-06-08 CRAN (R 3.3.2) #> png 0.1-7 2013-12-03 cran (@0.1-7) #> promises 1.0.1 2018-04-13 CRAN (R 3.4.4) #> R.methodsS3 1.7.1 2016-02-16 cran (@1.7.1) #> R.oo 1.22.0 2018-04-22 CRAN (R 3.4.4) #> R.utils 2.6.0 2017-11-05 CRAN (R 3.4.2) #> R6 2.2.2 2017-06-17 cran (@2.2.2) #> raster 2.6-7 2017-11-13 CRAN (R 3.4.2) #> RColorBrewer 1.1-2 2014-12-07 CRAN (R 3.3.2) #> Rcpp 0.12.16 2018-03-13 CRAN (R 3.4.4) #> RCurl 1.95-4.10 2018-01-04 CRAN (R 3.4.3) #> rgdal 1.2-20 2018-05-07 CRAN (R 3.4.4) #> rgeos 0.3-26 2017-10-31 cran (@0.3-26) #> rmapshaper 0.4.0 2018-04-24 Github (ateucher/rmapshaper@7a787d2) #> rmarkdown 1.9 2018-03-01 CRAN (R 3.4.4) #> RPostgreSQL 0.6-2 2017-06-24 CRAN (R 3.4.1) #> rprojroot 1.3-2 2018-01-03 CRAN (R 3.4.3) #> satellite 1.0.1 2017-10-18 CRAN (R 3.4.2) #> scales 0.5.0.9000 2017-11-06 Github (hadley/scales@d767915) #> sf * 0.6-3 2018-05-14 Github (r-spatial/sf@eb84d7f) #> shiny 1.0.5 2017-08-23 CRAN (R 3.4.1) #> sp 1.2-7 2018-01-19 cran (@1.2-7) #> spData * 0.2.8.8 2018-04-24 Github (nowosad/spData@8edd206) #> spDataLarge 0.2.6.3 2018-04-20 Github (nowosad/spDataLarge@22c826a) #> spdep 0.7-7 2018-04-03 CRAN (R 3.4.4) #> splines 3.4.4 2018-03-16 local #> stats * 3.4.4 2018-03-16 local #> stats4 3.4.4 2018-03-16 local #> stringi 1.2.2 2018-05-02 CRAN (R 3.4.4) #> stringr 1.3.1 2018-05-10 CRAN (R 3.4.4) #> tmap * 2.0 2018-05-14 Github (mtennekes/tmap@22af0de) #> tmaptools 2.0 2018-04-07 Github (mtennekes/tmaptools@01d1e9f) #> tools 3.4.4 2018-03-16 local #> udunits2 0.13 2016-11-17 cran (@0.13) #> units 0.5-1 2018-01-08 cran (@0.5-1) #> utils * 3.4.4 2018-03-16 local #> V8 1.5 2017-04-25 cran (@1.5) #> viridisLite 0.3.0 2018-02-01 cran (@0.3.0) #> webshot 0.5.0 2017-11-29 CRAN (R 3.4.2) #> withr 2.1.2 2018-04-07 Github (jimhester/withr@79d7b0d) #> XML 3.98-1.11 2018-04-16 cran (@3.98-1.) #> xml2 1.2.0 2018-01-24 CRAN (R 3.4.3) #> xtable 1.8-2 2016-02-05 cran (@1.8-2) #> yaml 2.1.19 2018-05-01 CRAN (R 3.4.4) ```
Robinlovelace commented 6 years ago

Update in further support of Tim's point: it works from the system command line:

image

jannes-m commented 6 years ago

Hey Martijn,

library("tmap")
library("spData")
tmap_mode("view")
qtm(world)

Running this, I can see Esri and OSM tiles but not CartoDB in the RStudio viewer. HTH. All the best, Jannes

mtennekes commented 6 years ago

Awesome, this type of collaboration, thanks all!

I'll stay with CartoDB then. Probably, RStudio will get this its major release within the next months. Besides, I still like it best for cartography.

tim-salabim commented 6 years ago

Yep, I will also not change though that thought had also crossed my mind. Also, it's also only an issue for quick viewing not for end production HTML which will likely be viewed in the browser anyway.

Robinlovelace commented 6 years ago

Update: I've just updated RStudio to the latest version and the cartodb tiles still fail. The other tiles work OK. I suggest others will experience this so suggest changing the default tiles, unless I'm missing something.

mtennekes commented 6 years ago

Ok, I switched to Esri WorldGrayCanvas, which is almost similar.

PS: it is also possible to set overlay tiles as an option. See https://github.com/mtennekes/tmap/blob/master/examples/tm_tiles.R (dontrun example)