Skip to content

Commit 549fba9

Browse files
committed
Add collaborate/cloud args to config for easy adding/removing
1 parent 91b6ffd commit 549fba9

File tree

4 files changed

+41
-31
lines changed

4 files changed

+41
-31
lines changed

R/layout.R

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,38 +57,48 @@ rangeslider <- function(p, ...) {
5757
#' @param p a plotly object
5858
#' @param ... these arguments are documented at
5959
#' \url{https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js}
60+
#' @param collaborate include the collaborate mode bar button (unique to the R pkg)?
61+
#' @param cloud include the send data to cloud button?
6062
#' @author Carson Sievert
6163
#' @export
62-
#' @examples \dontrun{
63-
#' config(plot_ly(), displaylogo = FALSE)
64-
#' }
64+
#' @examples
65+
#'
66+
#' config(plot_ly(), displaylogo = FALSE, collaborate = FALSE)
67+
#'
6568

66-
config <- function(p, ...) {
67-
attrs <- list(...)
68-
# make sure we have the right defaults
69+
config <- function(p, ..., collaborate = TRUE, cloud = FALSE) {
70+
71+
# make sure config is a list
6972
p$x$config <- p$x$config %||% list()
70-
p$x$config[["modeBarButtonsToRemove"]] <-
71-
p$x$config[["modeBarButtonsToRemove"]] %||% 'sendDataToCloud'
72-
p$x$config[["modeBarButtonsToAdd"]] <-
73-
p$x$config[["modeBarButtonsToAdd"]] %||% list(sharingButton())
7473

75-
# now accumulate
76-
p$x$config[["modeBarButtonsToAdd"]] <- c(
77-
p$x$config[["modeBarButtonsToAdd"]],
78-
attrs[["modeBarButtonsToAdd"]]
79-
)
80-
p$x$config[["modeBarButtonsToRemove"]] <- c(
81-
p$x$config[["modeBarButtonsToRemove"]],
82-
attrs[["modeBarButtonsToRemove"]]
83-
)
74+
nms <- sapply(p$x$config[["modeBarButtonsToAdd"]], "[[", "name")
75+
hasCollab <- sharingButton()[["name"]] %in% nms
76+
77+
if (collaborate && !hasCollab) {
78+
nAdd <- length(p$x$config[["modeBarButtonsToAdd"]])
79+
p$x$config[["modeBarButtonsToAdd"]][[nAdd + 1]] <- sharingButton()
80+
}
81+
if (!collaborate) {
82+
p$x$config[["modeBarButtonsToAdd"]][nms %in% sharingButton()[["name"]]] <- NULL
83+
}
84+
85+
hasCloud <- !'sendDataToCloud' %in% p$x$config[["modeBarButtonsToRemove"]]
86+
if (!cloud) {
87+
p$x$config[["modeBarButtonsToRemove"]] <- c(
88+
p$x$config[["modeBarButtonsToRemove"]], 'sendDataToCloud'
89+
)
90+
}
91+
if (cloud) {
92+
b <- p$x$config[["modeBarButtonsToRemove"]]
93+
p$x$config[["modeBarButtonsToRemove"]] <- b[!b %in% 'sendDataToCloud']
94+
}
8495

8596
# ensure array
8697
if (length(p$x$config[["modeBarButtonsToRemove"]]) == 1) {
8798
p$x$config[["modeBarButtonsToRemove"]] <- list(p$x$config[["modeBarButtonsToRemove"]])
8899
}
89100

90-
# overwrite the other arguments
91-
attrs <- attrs[!grepl("modeBarButtonsTo", names(attrs))]
92-
p$x$config <- modify_list(p$x$config, attrs)
101+
102+
p$x$config <- modify_list(p$x$config, list(...))
93103
p
94104
}

R/plotly_build.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ plotly_build.plotly <- function(p) {
325325
p <- verify_hovermode(p)
326326
# try to convert to webgl if toWebGl was used
327327
p <- verify_webgl(p)
328-
# populate R's non-default config
329-
p <- config(p)
328+
# make sure plots don't get sent out of the network (for enterprise)
330329
p$x$base_url <- get_domain()
331330
p
332331
}

inst/examples/plotlyLinkedClick/app.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# git checkout feature/transmit
2-
# R CMD install ./
3-
41
library(plotly)
52
library(shiny)
63

man/config.Rd

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)