Skip to content

Commit b8b4c94

Browse files
committed
add offline argument to plot_geo(); closes #356
1 parent 31d027d commit b8b4c94

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

Diff for: DESCRIPTION

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ Suggests:
6767
rgeos,
6868
png,
6969
IRdisplay,
70-
processx
70+
processx,
71+
plotlyGeoAssets
7172
Remotes:
7273
tidyverse/ggplot2
7374
LazyData: true

Diff for: R/plotly.R

+18-1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ plot_mapbox <- function(data = data.frame(), ...) {
253253
#'
254254
#' @param data A data frame (optional).
255255
#' @param ... arguments passed along to [plot_ly()].
256+
#' @param offline whether or not to include geo assets so that the map
257+
#' can be viewed with or without an internet connection. The plotlyGeoAssets
258+
#' package is required for this functionality.
256259
#' @export
257260
#' @author Carson Sievert
258261
#' @seealso [plot_ly()], [plot_mapbox()], [ggplotly()]
@@ -263,8 +266,22 @@ plot_mapbox <- function(data = data.frame(), ...) {
263266
#' plot_geo(x = ~long, y = ~lat) %>%
264267
#' add_markers(size = I(1))
265268
#'
266-
plot_geo <- function(data = data.frame(), ...) {
269+
plot_geo <- function(data = data.frame(), ..., offline = FALSE) {
267270
p <- plot_ly(data, ...)
271+
272+
if (isTRUE(offline)) {
273+
if (system.file(package = "plotlyGeoAssets") == "") {
274+
stop(
275+
"The plotlyGeoAssets package is required to make 'offline' maps. ",
276+
"Please install and try again.",
277+
call. = FALSE
278+
)
279+
}
280+
p$dependencies <- c(
281+
list(plotlyGeoAssets::geo_assets()),
282+
p$dependencies
283+
)
284+
}
268285
# not only do we use this for is_geo(), but also setting the layout attr
269286
# https://plot.ly/r/reference/#layout-geo
270287
p$x$layout$mapType <- "geo"

Diff for: 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)