@@ -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"
0 commit comments