Skip to content

Commit b9697c8

Browse files
committed
accumulate mode bar buttons
1 parent 92c0f0c commit b9697c8

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

R/layout.R

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,24 @@ rangeslider <- function(p, ...) {
6060
#' @author Carson Sievert
6161
#' @export
6262
#' @examples \dontrun{
63-
#' config(plot_ly(), displaylogo = FALSE, modeBarButtonsToRemove = list('sendDataToCloud'))
63+
#' config(plot_ly(), displaylogo = FALSE)
6464
#' }
6565

6666
config <- function(p, ...) {
67-
p$x$config <- modify_list(p$x$config, list(...))
67+
attrs <- list(...)
68+
# accumulate these attributes
69+
p$x$config[["modeBarButtonsToRemove"]] <- c(
70+
p$x$config[["modeBarButtonsToRemove"]] %||% 'sendDataToCloud',
71+
attrs[["modeBarButtonsToRemove"]]
72+
)
73+
if (length(p$x$config[["modeBarButtonsToRemove"]])) {
74+
p$x$config[["modeBarButtonsToRemove"]] <- list(p$x$config[["modeBarButtonsToRemove"]])
75+
}
76+
p$x$config[["modeBarButtonsToAdd"]] <- c(
77+
list(sharingButton()),
78+
attrs[["modeBarButtonsToAdd"]]
79+
)
80+
attrs <- attrs[grepl("modeBarButtonsTo", names(attrs))]
81+
p$x$config <- modify_list(p$x$config, attrs)
6882
p
6983
}

R/plotly_build.R

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,9 @@ plotly_build.plotly <- function(p) {
323323
p <- verify_hovermode(p)
324324
# try to convert to webgl if toWebGl was used
325325
p <- verify_webgl(p)
326-
327-
328-
# TODO: avoid overwritting user specified args
329-
p <- config(p,
330-
modeBarButtonsToRemove = I("sendDataToCloud"),
331-
modeBarButtonsToAdd = list(sharingButton())
332-
)
326+
# populate R's non-default config
327+
p <- config(p)
333328
p$x$base_url <- get_domain()
334-
335329
p
336330
}
337331

man/config.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)