Skip to content

Commit

Permalink
Merge pull request #122 from crazycapivara/feature/dynamic-deps
Browse files Browse the repository at this point in the history
Refactor dependencies
  • Loading branch information
crazycapivara committed Feb 24, 2020
2 parents 28a8892 + cadef71 commit 099ca05
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 597 deletions.
5 changes: 3 additions & 2 deletions R/basemap.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#' Add a basemap to the deckgl widget
#'
#' @inheritParams add_mapbox_basemap
#' @param style The style definition of the map conforming to the Mapbox Style Specification.
#' @param ... not used
#' @export
add_basemap <- function(style = use_carto_style(), ...) {
add_mapbox_basemap(style, ...)
add_basemap <- function(deckgl, style = use_carto_style(), ...) {
add_mapbox_basemap(deckgl, style, ...)
}
2 changes: 1 addition & 1 deletion R/deckgl.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ deckgl <- function(latitude = 37.8, longitude = -122.45, zoom = 12, pitch = 0, b
height = height,
package = "deckgl",
elementId = elementId,
dependencies = deckgl_dependencies()
dependencies = use_deps("deck.gl") # deckgl_dependencies()
)
}

Expand Down
66 changes: 44 additions & 22 deletions R/dependencies.R
Original file line number Diff line number Diff line change
@@ -1,28 +1,50 @@
deckgl_dependencies <- function() {
list(
htmltools::htmlDependency(
"deckgl",
version = "8.0.15",
src = system.file("htmlwidgets/lib/deckgl", package = "deckgl"),
script = c("dist.min.js"),
stylesheet = "deckgl_.css",
all_files = FALSE
)
)
}
# /**
# * Obsolete
# */
#deckgl_dependencies <- function() {
# list(
# htmltools::htmlDependency(
# "deckgl",
# version = "8.0.16",
# src = system.file("htmlwidgets/lib/deckgl", package = "deckgl"),
# script = c("dist.min.js"),
# stylesheet = "deckgl_.css",
# all_files = FALSE
# )
# )
#}

# - name: h3-js
# version: 3.4.3
# src: htmlwidgets/lib/h3
# script: h3-js.umd.js
h3_dependencies <- function() {
list(
htmltools::htmlDependency(
"h3-js",
version = "3.4.3",
src = system.file("htmlwidgets/lib/h3", package = "deckgl"),
script = c("h3-js.umd.js"),
all_files = FALSE
)
)
# /**
# * Obsolete
# */
#h3_dependencies <- function() {
# list(
# htmltools::htmlDependency(
# "h3-js",
# version = "3.4.3",
# src = system.file("htmlwidgets/lib/h3", package = "deckgl"),
# script = c("h3-js.umd.js"),
# all_files = FALSE
# )
# )
#}

read_deps <- function() {
system.file("htmlwidgets/deps.yaml", package = "deckgl") %>%
yaml::read_yaml()
}

use_deps <- function(dep_names) {
deps <- read_deps()
if (!all(dep_names %in% names(deps))) {
stop("available deps [", paste(names(deps), collapse = ", "), "]")
}

lapply(deps[dep_names], function(dep) {
do.call(htmltools::htmlDependency, dep)
})
}
2 changes: 1 addition & 1 deletion R/layers_h3-cluster-layer.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#' @example inst/examples/deckgl-api-reference/h3-cluster-layer.R
#' @export
add_h3_cluster_layer <- function(deckgl, id = "h3-cluster-layer", data = NULL, properties = list(), ...) {
deckgl$dependencies <- c(h3_dependencies(), deckgl$dependencies)
deckgl$dependencies <- c(use_deps("h3-js"), deckgl$dependencies)
add_layer(deckgl, "H3ClusterLayer", id, data, properties, ...)
}
2 changes: 1 addition & 1 deletion R/layers_h3-hexagon-layer.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#' @example inst/examples/deckgl-api-reference/h3-hexagon-layer.R
#' @export
add_h3_hexagon_layer <- function(deckgl, id = "h3-hexagon-layer", data = NULL, properties = list(), ...) {
deckgl$dependencies <- c(h3_dependencies(), deckgl$dependencies)
deckgl$dependencies <- c(use_deps("h3-js"), deckgl$dependencies)
add_layer(deckgl, "H3HexagonLayer", id, data, properties, ...)
}
10 changes: 3 additions & 7 deletions R/mapboxgl_basemap.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
#' @param deckgl deckgl widget
#' @param style map style
#' @param token mapbox API access token
#'
#' @return deckgl widget
#'
#' @export
add_mapbox_basemap <- function(deckgl, style = "mapbox://styles/mapbox/light-v9", token = Sys.getenv("MAPBOX_API_TOKEN")) {
deckgl$dependencies <- c(
deckgl$dependencies,
mapboxgl_dependencies()
)
add_mapbox_basemap <- function(deckgl, style = "mapbox://styles/mapbox/light-v9",
token = Sys.getenv("MAPBOX_API_TOKEN")) {
deckgl$dependencies <- c(deckgl$dependencies, use_deps("mapbox-gl"))
deckgl$x$mapStyle <- style
deckgl$x$mapboxApiAccessToken <- token
deckgl
Expand Down
27 changes: 15 additions & 12 deletions R/mapboxgl_dependencies.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
mapboxgl_dependencies <- function() {
list(
htmltools::htmlDependency(
"mapbox-gl",
version = "0.48.0",
src = system.file("htmlwidgets/lib/mapboxgl", package = "deckgl"),
script = c("mapbox-gl.js"),
stylesheet = "mapbox-gl.css",
all_files = FALSE
)
)
}
# /**
# * Obsolete
# */
#mapboxgl_dependencies <- function() {
# list(
# htmltools::htmlDependency(
# "mapbox-gl",
# version = "1.8.0",
# src = system.file("htmlwidgets/lib/mapboxgl", package = "deckgl"),
# script = c("mapbox-gl.js"),
# stylesheet = "mapbox-gl.css",
# all_files = FALSE
# )
# )
#}
4 changes: 1 addition & 3 deletions R/package.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
deckgljs_version <- function() {
# filename <- system.file("htmlwidgets/deckgl.yaml", package = "deckgl")
# yaml::yaml.load_file(filename)$dependencies[[1]]$version
deckgl_dependencies()[[1]]$version
use_deps("deck.gl")$deck.gl$version
}

browse_api_examples <- function() {
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}

packageStartupMessage(
pkgname, " ", getNamespaceVersion(pkgname), " wrapping deckgljs ", deckgljs_version(), "\n",
pkgname, " ", getNamespaceVersion(pkgname), " wrapping deck.gl.js ", deckgljs_version(), "\n",
" Documentation: https://crazycapivara.github.io/deckgl/\n",
" Issues, notes and bleeding edge: https://github.com/crazycapivara/deckgl\n",
mapbox_message
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ library(deckgl)
# An R Interface to deck.gl

[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/deckgl)](https://cran.r-project.org/package=deckgl) [![Travis-CI Build Status](https://travis-ci.org/crazycapivara/deckgl.svg?branch=master)](https://travis-ci.org/crazycapivara/deckgl) [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![deck.gl Version](https://img.shields.io/badge/deck.gl-v8.0.15-blue.svg)](https://github.com/uber/deck.gl/releases/tag/v8.0.15)
[![deck.gl Version](https://img.shields.io/badge/deck.gl-v8.0.16-blue.svg)](https://github.com/uber/deck.gl/releases/tag/v8.0.16)

Deckgl for R makes the open-source JavaScript library [deck.gl](https://deck.gl/) available within R via the [htmlwidgets](https://www.htmlwidgets.org/) package.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
An R Interface to deck.gl
=========================

[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/deckgl)](https://cran.r-project.org/package=deckgl) [![Travis-CI Build Status](https://travis-ci.org/crazycapivara/deckgl.svg?branch=master)](https://travis-ci.org/crazycapivara/deckgl) [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![deck.gl Version](https://img.shields.io/badge/deck.gl-v8.0.15-blue.svg)](https://github.com/uber/deck.gl/releases/tag/v8.0.15)
[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/deckgl)](https://cran.r-project.org/package=deckgl) [![Travis-CI Build Status](https://travis-ci.org/crazycapivara/deckgl.svg?branch=master)](https://travis-ci.org/crazycapivara/deckgl) [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![deck.gl Version](https://img.shields.io/badge/deck.gl-v8.0.16-blue.svg)](https://github.com/uber/deck.gl/releases/tag/v8.0.16)

Deckgl for R makes the open-source JavaScript library [deck.gl](https://deck.gl/) available within R via the [htmlwidgets](https://www.htmlwidgets.org/) package.

Expand Down
23 changes: 23 additions & 0 deletions inst/htmlwidgets/deps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
deck.gl:
name: deck.gl
version: 8.0.16
src: htmlwidgets/lib/deckgl
script: dist.min.js
stylesheet: deckgl_.css
all_files: false
package: deckgl
mapbox-gl:
name: mapbox-gl
version: 1.8.0
src: htmlwidgets/lib/mapboxgl
script: mapbox-gl.js
stylesheet: mapbox-gl.css
all_files: false
package: deckgl
h3-js:
name: h3-js
version: 3.4.3
src: htmlwidgets/lib/h3
script: h3-js.umd.js
all_files: false
package: deckgl
4 changes: 2 additions & 2 deletions inst/htmlwidgets/lib/deckgl/dist.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 099ca05

Please sign in to comment.