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

docs: Convert website to use {pkgdown} #902

Merged
merged 16 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@
^revdep$
^CRAN-SUBMISSION$
^_dev$
^vignettes/articles$
^_pkgdown\.yml$
olivroy marked this conversation as resolved.
Show resolved Hide resolved
^pkgdown$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ revdep/checks.noindex
revdep/library.noindex
revdep/data.sqlite
viztest-*
inst/doc
docs
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ Suggests:
purrr,
R6,
RJSONIO,
rmarkdown,
s2,
sf (>= 0.9-6),
shiny,
terra,
testthat (>= 3.0.0)
Config/testthat/edition: 3
Config/Needs/website: geojsonio, ncdf4
olivroy marked this conversation as resolved.
Show resolved Hide resolved
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
VignetteBuilder: knitr
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ S3method(polygonData,matrix)
S3method(polygonData,sf)
S3method(polygonData,sfc)
S3method(polygonData,sfg)
S3method(toPaletteFunc,"function")
S3method(toPaletteFunc,character)
S3method(toPaletteFunc,matrix)
S3method(to_multipolygon,Lines)
S3method(to_multipolygon,MULTILINESTRING)
S3method(to_multipolygon,MULTIPOLYGON)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* Fixed #893: Correctly call `terra::crs()` when checking the CRS of a `SpatVector` object in `pointData()` or `polygonData()` (thanks @mkoohafkan, #894).

* leaflet now has a brand new pkgdown site (@olivroy, #902)
olivroy marked this conversation as resolved.
Show resolved Hide resolved

# leaflet 2.2.1

* When `addProviderTiles()` is used with `{leaflet.providers}` version 2.0.0 or later, the `leaflet-providers` HTML dependency produced can be correctly cached by knitr. When used with older versions of `{leaflet.providers}`, the HTML dependency uses temp files that break knitr's caching mechanism (thanks @qdread, @jaredlander; #884).
Expand Down
3 changes: 3 additions & 0 deletions R/colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ brewer_pal <- function(palette, n = NULL) {

# Strings are interpreted as color names, unless length is 1 and it's the name
# of an RColorBrewer palette that is marked as qualitative
#' @export
toPaletteFunc.character <- function(pal, alpha, nlevels) {
if (length(pal) == 1 && pal %in% row.names(RColorBrewer::brewer.pal.info)) {
paletteInfo <- RColorBrewer::brewer.pal.info[pal, ]
Expand All @@ -341,11 +342,13 @@ toPaletteFunc.character <- function(pal, alpha, nlevels) {
}

# Accept colorRamp style matrix
#' @export
toPaletteFunc.matrix <- function(pal, alpha, nlevels) {
toPaletteFunc(rgb(pal, maxColorValue = 255), alpha = alpha)
}

# If a function, just assume it's already a function over [0-1]
#' @export
toPaletteFunc.function <- function(pal, alpha, nlevels) {
pal
}
Expand Down
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
url: ~
template:
bootstrap: 5

olivroy marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
olivroy marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions inst/examples/highlight-polygons.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#' An example to show how to highlight polygons on hover using `onRender`
#'
library(sp)
library(albersusa)
library(maptools)
library(albersusa) # Requires rgdal / rgeos archived.
olivroy marked this conversation as resolved.
Show resolved Hide resolved
library(leaflet)

spdf <- rmapshaper::ms_simplify(usa_composite())
Expand Down
2 changes: 1 addition & 1 deletion inst/examples/proj4Leaflet.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ leaflet(options = leafletOptions(


library(sp)
library(albersusa)
library(albersusa) # requires rgdal and maptools (archived)
spdf <- rmapshaper::ms_simplify(usa_composite())
pal <- colorNumeric(
palette = "Blues",
Expand Down
2 changes: 2 additions & 0 deletions vignettes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.html
*.R
10 changes: 9 additions & 1 deletion docs/basemaps.Rmd → vignettes/articles/basemaps.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
---
schloerke marked this conversation as resolved.
Show resolved Hide resolved
pagetitle: Leaflet for R - Using Basemaps
title: "Using Basemaps"
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

## Using Basemaps

Leaflet supports basemaps using [map tiles](https://www.mapbox.com/guides/how-web-maps-work/), popularized by Google Maps and now used by nearly all interactive web maps.
Expand All @@ -11,6 +18,7 @@ Leaflet supports basemaps using [map tiles](https://www.mapbox.com/guides/how-we
The easiest way to add tiles is by calling `addTiles()` with no arguments; by default, [OpenStreetMap](https://www.openstreetmap.org/) tiles are used.

```{r fig.height=2.5}
library(leaflet)
m <- leaflet() %>% setView(lng = -71.0589, lat = 42.3601, zoom = 12)
m %>% addTiles()
```
Expand Down
9 changes: 7 additions & 2 deletions docs/choropleths.Rmd → vignettes/articles/choropleths.Rmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
---
pagetitle: Leaflet for R - Choropleths
title: "Choropleths"
---

## Choropleths
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

Making choropleths with leaflet is easy. In this example, we'll duplicate the [step-by-step choropleth tutorial](https://leafletjs.com/examples/choropleth/) from the Leaflet.js website.

Expand Down
9 changes: 8 additions & 1 deletion docs/colors.Rmd → vignettes/articles/colors.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
---
pagetitle: Leaflet for R - Colors
title: "Add color to a leaflet"
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

## Colors

An important part of spatial visualization is mapping variables to colors. While R has no shortage of built-in functionality to map values to colors, we found that there was enough friction in the process to warrant introducing some wrapper functions that do a lot of the work for you.
Expand Down
9 changes: 8 additions & 1 deletion docs/extending.Rmd → vignettes/articles/extending.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
---
pagetitle: Leaflet for R - Extending Leaflet
title: "Extending Leaflet"
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

## Extending Leaflet package

The Leaflet Javascript library has a plethora of [plugins](leafletjs.com/plugins) available that extend the functionality of the core package. We have incorporated a chosen few in the R package. It may be desirable to use plugins availble outside of what are supported by this pakage.
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
8 changes: 5 additions & 3 deletions docs/json.Rmd → vignettes/articles/json.Rmd
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
schloerke marked this conversation as resolved.
Show resolved Hide resolved
pagetitle: Leaflet for R - Working with GeoJSON & TopoJSON
title: "Working with GeoJSON & TopoJSON"
---


## Working with GeoJSON & TopoJSON

For working with GeoJSON/TopoJSON data you have two options: either read it into `sp` objects; or use the `addGeoJSON()` and `addTopoJSON()` functions.

### Reading as `sp`

The first approach is to use either `rgdal` or `geojsonio` (packages) to read GeoJSON/TopoJSON as `sp` objects. Then, you can use the full functionality of [polygons](shapes.html), [markers](markers.html), [colors](colors.html), [legends](legends.html), etc.
The first approach is to use either `sf` or `geojsonio` (packages) to read GeoJSON/TopoJSON as `sp` objects. Then, you can use the full functionality of [polygons](shapes.html), [markers](markers.html), [colors](colors.html), [legends](legends.html), etc.

```{r, include = FALSE}
library(leaflet)
Expand All @@ -18,7 +19,7 @@ library(magrittr)
```{r message=FALSE,warning=FALSE}
# From http://eric.clst.org/Stuff/USGeoJSON and
# https://en.wikipedia.org/wiki/List_of_United_States_counties_and_county_equivalents
nycounties <- rgdal::readOGR("https://rstudio.github.io/leaflet/json/nycounties.geojson")
nycounties <- sf::read_sf("https://rstudio.github.io/leaflet/json/nycounties.geojson")
# Or use the geojsonio equivalent:
# nycounties <- geojsonio::geojson_read("https://rstudio.github.io/leaflet/json/nycounties.geojson", what = "sp")

Expand Down Expand Up @@ -70,6 +71,7 @@ The previous example demonstrated the style arguments. Below is a more involved
```{r echo=FALSE,warning=FALSE,message=FALSE}
library(jsonlite, quietly = TRUE)
```

```{r}
library(jsonlite)

Expand Down
10 changes: 8 additions & 2 deletions docs/legends.Rmd → vignettes/articles/legends.Rmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
---
pagetitle: Leaflet for R - Legends
title: "Legends"
---

## Legends
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```


The Leaflet package includes convenience functions for creating color legends. In this section, we will build on the example from the [Colors](colors.html) page.

Expand Down
13 changes: 11 additions & 2 deletions docs/markers.Rmd → vignettes/articles/markers.Rmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
---
pagetitle: Leaflet for R - Markers
title: "Markers"
---

## Markers
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

```{r,echo=FALSE}
library(leaflet)
```

Use markers to call out points on the map. Marker locations are expressed in latitude/longitude coordinates, and can either appear as icons or as circles.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
pagetitle: Leaflet for R - More features
title: "More features"
---


## Additional features

- Add-ons
Expand Down
File renamed without changes.
15 changes: 13 additions & 2 deletions docs/popups.Rmd → vignettes/articles/popups.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
---
pagetitle: Leaflet for R - Popups and Labels
title: "Popups and Labels"
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

```{r, include = FALSE}
library(leaflet)
```

## Popups

Popups are small boxes containing arbitrary HTML, that point to a specific point on the map.
Expand Down Expand Up @@ -94,4 +105,4 @@ leaflet() %>% addTiles() %>% setView(-118.456554, 34.09, 13) %>%

#### Labels without markers

You can create labels without the accompanying markers using the `addLabelOnlyMarkers` function.
You can create labels without the accompanying markers using the `addLabelOnlyMarkers()` function.
18 changes: 13 additions & 5 deletions docs/projections.Rmd → vignettes/articles/projections.Rmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
---
pagetitle: Leaflet for R - Using Projections
title: "Working with projections in Leaflet"
---

## Working with projections in Leaflet
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

```{r, include = FALSE}
library(leaflet)
```

**Note:** This functionality is for advanced users and may not be supported across all functions (for example, `addRasterImage` currently works only with EPSG:3857 Web Mercator).

Expand Down Expand Up @@ -69,10 +78,9 @@ While tiles must be in the same projection as used in the `leafletCRS` function,

This example uses [EPSG:2163](http://epsg.io/2163) (US National Atlas Equal Area projection). The dataset we use (`usa_sf` from the `albersusa` package, though we're not actually using Albers projection here) has Alaska and Hawaii moved closer to mainland US as well as rotated and resized accordingly.

```{r message=FALSE,warning=FALSE}
```{r message=FALSE,warning=FALSE,eval=FALSE}
library(sp)
library(albersusa)

library(albersusa) # not possible to install due to rgdal archival.
spdf <- rmapshaper::ms_simplify(usa_sf(), keep = 0.1)
pal <- colorNumeric("Blues", domain = spdf$pop_2014)
epsg2163 <- leafletCRS(
Expand Down
12 changes: 9 additions & 3 deletions docs/raster.Rmd → vignettes/articles/raster.Rmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
---
pagetitle: Leaflet for R - Raster Images
title: "Raster Images"
---

## Raster Images
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

Two-dimensional `SpatRaster` objects (from the [`terra` package](https://CRAN.R-project.org/package=terra)) or `RasterLayer` objects (from the [`raster` package](https://CRAN.R-project.org/package=raster)) can be turned into images and added to Leaflet maps using the `addRasterImage` function.

Expand Down Expand Up @@ -41,12 +46,13 @@ suppressPackageStartupMessages({
library(raster)
r <- suppressWarnings(raster("nc/oisst-sst.nc"))
})
library(leaflet)
# ncdf4 emits partial match warnings
```

```{r eval=FALSE}
library(raster)

library(leaflet)
r <- raster("nc/oisst-sst.nc")
```

Expand Down
21 changes: 14 additions & 7 deletions docs/shapes.Rmd → vignettes/articles/shapes.Rmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
---
pagetitle: Leaflet for R - Shapes
title: "Lines and Shapes"
---

## Lines and Shapes
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

```{r,echo=FALSE}
library(leaflet)
library(magrittr)
```

Leaflet makes it easy to take spatial lines and shapes from R and add them to maps.

Expand All @@ -16,9 +26,6 @@ Line and polygon data can come from a variety of sources:
* `map` objects (from the `maps` package's `map()` function); use `map(fill = TRUE)` for polygons, `FALSE` for polylines
* Two-column numeric matrix; the first column is longitude and the second is latitude. Polygons are separated by rows of `(NA, NA)`. It is not possible to represent multi-polygons nor polygons with holes using this method; use `SpatialPolygons` instead.

```{r echo=FALSE,results='hide',message=FALSE,warning=FALSE}
library(rgdal, quietly = TRUE)
```
```{r states,message=FALSE,warning=FALSE}
# From https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html
states <- sf::st_read("shp/cb_2013_us_state_20m.shp",
Expand All @@ -44,8 +51,8 @@ The above example uses the `highlightOptions` parameter to emphasize the current

Very detailed (i.e. large) shape data can present a problem for Leafet, since it is all eventually passed into the browser and rendered as SVG, which is very expressive and convenient but has scalability limits. In these cases, consider using `rmapshaper::ms_simplify`, which does topology-preserving simplification conveniently from R.

```{r message=FALSE,warning=FALSE}
library(albersusa)
```{r message=FALSE,warning=FALSE,eval=FALSE}
library(albersusa) # Requires rgdal, archived.

fullsize <- usa_sf()
object.size(fullsize)
Expand Down
Loading
Loading