Skip to content

Commit

Permalink
getting pkgdown to work
Browse files Browse the repository at this point in the history
looks like an outdated dependency was the issue (evaluate pkg) ref: https://forum.posit.co/t/build-site-failing-to-parse-roxygen-rd/189331
  • Loading branch information
romartinez-nycc committed Sep 30, 2024
1 parent f770ea3 commit 06f0a60
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 32 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown.yaml

permissions: read-all

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ Suggests: here,
extrafont,
sf
RoxygenNote: 7.2.3
URL: https://newyorkcitycouncil.github.io/councildown/
81 changes: 49 additions & 32 deletions R/addCouncilStyle.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
#' @param highlight_dists a vector including the numbers of council districts that you would like to use a non-standard color for the numeric label. Especially useful when using the "cool" palette with council districts as the label color here blends right in.
#' @param dist_year Either "2013" (for 2013-2023 lines) or "2023" (for 2023-2033 lines).
#' @param highlight_color used IF you specify a list of highlight_dists as the color for their text. Defaults to white
#' @param minZoom Minimum zoom level for the map. Defaults to 10.
#' @param maxZoom Maximum zoom level for the map. Defaults to 15.
#'
#' @return A \code{leaflet} map that in has City Council styles, including tiles,
#' council district outlines, and fonts
#' @export
#'
#' @examples
#' library(leaflet)
#' library(councildown)
#' leaflet() %>%
#' addCouncilStyle(add_dists=TRUE)
#'

addCouncilStyle <- function(map, add_dists = FALSE, highlight_dists = NULL, dist_year = "2013",
highlight_color = "#cdd9f1", minZoom = 10, maxZoom = 15) {
#' @export
addCouncilStyle <- function(map,
add_dists = FALSE,
highlight_dists = NULL,
dist_year = "2013",
highlight_color = "#cdd9f1",
minZoom = 10, maxZoom = 15)
{
# Adds min and max Zoom
map$x$options$minZoom = minZoom
map$x$options$maxZoom = maxZoom
Expand All @@ -31,43 +37,51 @@ addCouncilStyle <- function(map, add_dists = FALSE, highlight_dists = NULL, dist
L.control.zoom({ position: 'topright' }).addTo(this)
}")


if(add_dists) {
if(dist_year != "2013" & dist_year != "2023") {stop("The dist_year you have entered is invalid. Choose either '2013' or '2023'")}
if(dist_year == "2013") {dists <- councildown::nycc_cd_13} else {dists <- councildown::nycc_cd_23}
if(dist_year != "2013" & dist_year != "2023")
{stop("The dist_year you have entered is invalid. Choose either '2013' or '2023'")}
if(dist_year == "2013") {dists <- councildown::nycc_cd_13}
else {dists <- councildown::nycc_cd_23}

map <- map %>%
leaflet::addPolygons(data = dists, fill = FALSE, weight = 1,
color = "#2F56A6", opacity = .5, smoothFactor = 0,
leaflet::addPolygons(data = dists,
fill = FALSE,
weight = 1,
color = "#2F56A6",
opacity = .5,
smoothFactor = 0,
group = "Council Districts") %>%
leaflet::addLabelOnlyMarkers(data = dists, lat = ~lab_y, lng = ~lab_x, label = ~coun_dist,
labelOptions = leaflet::labelOptions(permanent = TRUE, noHide = TRUE,
textOnly = TRUE,
textsize = 12,
direction = "center",
style = list(color = "#23417D",
"font-family" = "'Open Sans', sans-serif",
"font-weight" = "bold")))
leaflet::addLabelOnlyMarkers(data = dists,
lat = ~lab_y, lng = ~lab_x,
label = ~coun_dist,
labelOptions =
leaflet::labelOptions(permanent = TRUE,
noHide = TRUE,
textOnly = TRUE,
textsize = 12,
direction = "center",
style =
list(color = "#23417D", "font-family" = "'Open Sans', sans-serif", "font-weight" = "bold")))

if (length(highlight_dists) > 0) {

map <- map %>%
leaflet::addLabelOnlyMarkers(data = dists[dists$coun_dist %in% highlight_dists, ],
lat = ~lab_y, lng = ~lab_x, label = ~coun_dist,
labelOptions = leaflet::labelOptions(permanent = TRUE, noHide = TRUE,
textOnly = TRUE,
textsize = 12,
direction = "center",
style = list(color = highlight_color,
"font-family" = "'Open Sans', sans-serif",
"font-weight" = "bold")))
labelOptions = leaflet::labelOptions
(permanent = TRUE, noHide = TRUE,
textOnly = TRUE, textsize = 12,
direction = "center",
style = list(color = highlight_color,
"font-family" = "'Open Sans',
sans-serif", "font-weight" = "bold")))
}
}

return(map)
}


#'
#'
#' Add a "Source" note to a leaflet that will be a static output
#'
#' @param map A \code{leaflet} map
Expand All @@ -76,8 +90,10 @@ addCouncilStyle <- function(map, add_dists = FALSE, highlight_dists = NULL, dist
#' @param fontSize font size of source text
#'
#' @return A \code{leaflet} map with a source note added in the bottom right for the councildown defined NYC frame
#'
#' @export
addSourceText <- function(map, source_text, color = "#555555", fontSize = "15px", ...) {
addSourceText <- function(map, source_text, color = "#555555",
fontSize = "15px", ...) {

geo = sf::st_sfc(sf::st_point(c(-73.645, 40.5)))
source_notes_geo = sf::st_sf(source = source_text,
Expand All @@ -95,34 +111,34 @@ addSourceText <- function(map, source_text, color = "#555555", fontSize = "15px"
return(map)

}


#'
#'
#' Wrapper for addPolygons
#'
#' All the same inputs apply as the leaflet::addPolygons function, we just use this wrapper to define the "defaults" for certain inputs
#'
#' @param map A \code{leaflet} map
#'
#' @return A \code{leaflet} map with polygons added
#' @export
#'
#' @export
addPolygons <- function(map, smoothFactor = 0, weight = 0, ...) {
map = map %>%
leaflet::addPolygons(smoothFactor = smoothFactor,
weight = weight, ...)

return(map)
}

#'
#' Wrapper for colorBin
#'
#' All the same inputs apply as the leaflet::colorBin function, just use this wrapper to define the "defaults" for certain inputs
#'
#' @param domain Possible values to be mapped by \code{leaflet}
#'
#' @return A \code{leaflet} colorBin palette
#' @export
#'
#' @export
colorBin <- function(palette = "nycc_blue", domain = NULL,
bins = 7, na.color = "#FFFFFF", ...) {
if((length(bins) == 1 & bins[1] > 7) | length(bins) > 7){
Expand All @@ -136,3 +152,4 @@ colorBin <- function(palette = "nycc_blue", domain = NULL,
domain = domain
)
}
#'
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
url: https://newyorkcitycouncil.github.io/councildown/
template:
bootstrap: 5

4 changes: 4 additions & 0 deletions man/addCouncilStyle.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 06f0a60

Please sign in to comment.