Skip to content

Instantly share code, notes, and snippets.

@tim-salabim
Created January 21, 2017 15:21
Show Gist options
  • Save tim-salabim/ba787b378720c3928dcf150345c35eb5 to your computer and use it in GitHub Desktop.
Save tim-salabim/ba787b378720c3928dcf150345c35eb5 to your computer and use it in GitHub Desktop.
# devtools::install_github("rstudio/leaflet", force = TRUE)
library(leaflet)
library(sf)
### polygons --------------------------------------------------------------
poldata <- st_as_sf(mapview::gadmCHE)
class(poldata)
class(st_geometry(poldata))
class(st_geometry(poldata)[[1]])
leaflet() %>% addTiles() %>% addPolygons(data = poldata)
leaflet() %>% addTiles() %>% addPolygons(data = st_geometry(poldata))
leaflet() %>% addTiles() %>% addPolygons(data = st_geometry(poldata)[[1]]) # error
### lines -----------------------------------------------------------------
lindata <- st_as_sf(mapview::atlStorms2005)
class(lindata)
class(st_geometry(lindata))
class(st_geometry(lindata)[[1]])
leaflet() %>% addTiles() %>% addPolylines(data = lindata) # error
leaflet() %>% addTiles() %>% addPolylines(data = st_geometry(lindata)) # error
leaflet() %>% addTiles() %>% addPolylines(data = st_geometry(lindata)[[1]]) # error
### points ----------------------------------------------------------------
ptsdata <- st_as_sf(mapview::breweries91)
class(ptsdata)
class(st_geometry(ptsdata))
class(st_geometry(ptsdata)[[1]])
leaflet() %>% addTiles() %>% addCircleMarkers(data = ptsdata)
leaflet() %>% addTiles() %>% addCircleMarkers(data = st_geometry(ptsdata))
leaflet() %>% addTiles() %>% addCircleMarkers(data = st_geometry(ptsdata)[[1]]) # error
@tim-salabim
Copy link
Author

my sessionInfo for this gist is:

R version 3.3.2 (2016-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=de_DE.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=de_DE.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] sf_0.2-8           leaflet_1.0.2.9010

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.8       plyr_1.8.4        git2r_0.15.0      R.methodsS3_1.7.1
 [5] R.utils_2.4.0     iterators_1.0.8   tools_3.3.2       gdalUtils_2.0.1.7
 [9] digest_0.6.11     jsonlite_1.2      viridisLite_0.1.3 satellite_0.3.0  
[13] memoise_1.0.0     lattice_0.20-34   png_0.1-7         foreach_1.4.3    
[17] shiny_0.14.2      DBI_0.5-1         crosstalk_1.0.1   yaml_2.1.14      
[21] curl_2.1          rgdal_1.2-4       geojsonio_0.2.0   quickmapr_0.2.0  
[25] withr_1.0.2       httr_1.2.1        raster_2.5-8      rgeos_0.3-20     
[29] htmlwidgets_0.8   devtools_1.12.0   webshot_0.3.2     stats4_3.3.2     
[33] grid_3.3.2        R6_2.2.0          foreign_0.8-67    sp_1.2-4         
[37] udunits2_0.13     magrittr_1.5      maptools_0.8-39   scales_0.4.1     
[41] codetools_0.2-15  htmltools_0.3.5   units_0.4-1       colorspace_1.2-6 
[45] mime_0.5          xtable_1.8-2      geosphere_1.5-5   httpuv_1.3.3     
[49] mapview_1.2.26    V8_1.1            munsell_0.4.3     R.oo_1.20.0    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment