Skip to content

Commit 25ce2cb

Browse files
authored
Merge pull request #1276 from ropensci/geo-assets
add offline argument to plot_geo(); closes #356
2 parents d20bda8 + b54904b commit 25ce2cb

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

DESCRIPTION

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Suggests:
6969
png,
7070
IRdisplay,
7171
processx,
72+
plotlyGeoAssets,
7273
rstudioapi
7374
Remotes:
7475
tidyverse/ggplot2

R/plotly.R

+18-1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ plot_mapbox <- function(data = data.frame(), ...) {
257257
#'
258258
#' @param data A data frame (optional).
259259
#' @param ... arguments passed along to [plot_ly()].
260+
#' @param offline whether or not to include geo assets so that the map
261+
#' can be viewed with or without an internet connection. The plotlyGeoAssets
262+
#' package is required for this functionality.
260263
#' @export
261264
#' @author Carson Sievert
262265
#' @seealso [plot_ly()], [plot_mapbox()], [ggplotly()]
@@ -267,8 +270,22 @@ plot_mapbox <- function(data = data.frame(), ...) {
267270
#' plot_geo(x = ~long, y = ~lat) %>%
268271
#' add_markers(size = I(1))
269272
#'
270-
plot_geo <- function(data = data.frame(), ...) {
273+
plot_geo <- function(data = data.frame(), ..., offline = FALSE) {
271274
p <- plot_ly(data, ...)
275+
276+
if (isTRUE(offline)) {
277+
if (system.file(package = "plotlyGeoAssets") == "") {
278+
stop(
279+
"The plotlyGeoAssets package is required to make 'offline' maps. ",
280+
"Please install and try again.",
281+
call. = FALSE
282+
)
283+
}
284+
p$dependencies <- c(
285+
list(plotlyGeoAssets::geo_assets()),
286+
p$dependencies
287+
)
288+
}
272289
# not only do we use this for is_geo(), but also setting the layout attr
273290
# https://plot.ly/r/reference/#layout-geo
274291
p$x$layout$mapType <- "geo"

man/plot_geo.Rd

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)