Skip to content

Commit 15fbb98

Browse files
authored
Merge pull request #742 from ropensci/feature/sharing
Feature/sharing
2 parents 0e23177 + f7bc521 commit 15fbb98

File tree

6 files changed

+46
-6
lines changed

6 files changed

+46
-6
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## CHANGES
44

55
* Now requires a version of __ggplot2__ higher than 2.1.0 because the new ggproto faceting infrastructure introduced breaking changes.
6+
* A book icon is added to the mode bar, by default, which links to the plotly book. If you want to remove this icon from a plot `p`, do `config(p, modeBarButtonsToRemove = "Collaborate")`
67

78
## BUG FIXES
89

R/layout.R

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,26 @@ 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+
# include the plotly book collaboration link?
74+
removeCollab <- "Collaborate" %in% p$x$config[["modeBarButtonsToRemove"]]
75+
if (length(p$x$config[["modeBarButtonsToRemove"]])) {
76+
p$x$config[["modeBarButtonsToRemove"]] <- list(p$x$config[["modeBarButtonsToRemove"]])
77+
}
78+
p$x$config[["modeBarButtonsToAdd"]] <- c(
79+
if (!removeCollab) list(sharingButton()),
80+
attrs[["modeBarButtonsToAdd"]]
81+
)
82+
attrs <- attrs[grepl("modeBarButtonsTo", names(attrs))]
83+
p$x$config <- modify_list(p$x$config, attrs)
6884
p
6985
}

R/plotly.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ plot_ly <- function(data = data.frame(), ..., type = NULL,
144144
# sane margin defaults (mainly for RStudio)
145145
margin = list(b = 40, l = 60, t = 25, r = 10)
146146
),
147-
config = list(modeBarButtonsToRemove = I("sendDataToCloud")),
148-
base_url = get_domain(),
149-
# TODO: make this trace specific when we merge with crosstalk branch
150147
source = source
151148
)
152149

R/plotly_build.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +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+
# populate R's non-default config
327+
p <- config(p)
328+
p$x$base_url <- get_domain()
326329
p
327330
}
328331

R/sharingButton.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
sharingButton <- function() {
2+
url <- 'https://cpsievert.github.io/plotly_book/plot-ly-for-collaboration.html'
3+
list(
4+
name = "Collaborate",
5+
icon = list(
6+
width = 1800,
7+
ascent = 1500,
8+
descent = -150,
9+
path = sharingPath
10+
),
11+
click = htmlwidgets::JS(sprintf(
12+
"function(gd) {
13+
// is this being viewed in RStudio?
14+
if (location.search == '?viewer_pane=1') {
15+
alert('To learn about plotly for collaboration, visit:\\n %s');
16+
} else {
17+
window.open('%s', '_blank');
18+
}
19+
}", url, url))
20+
)
21+
}
22+
23+
sharingPath <- 'M1703 478q40 57 18 129l-275 906q-19 64-76.5 107.5t-122.5 43.5h-923q-77 0-148.5-53.5t-99.5-131.5q-24-67-2-127 0-4 3-27t4-37q1-8-3-21.5t-3-19.5q2-11 8-21t16.5-23.5 16.5-23.5q23-38 45-91.5t30-91.5q3-10 .5-30t-.5-28q3-11 17-28t17-23q21-36 42-92t25-90q1-9-2.5-32t.5-28q4-13 22-30.5t22-22.5q19-26 42.5-84.5t27.5-96.5q1-8-3-25.5t-2-26.5q2-8 9-18t18-23 17-21q8-12 16.5-30.5t15-35 16-36 19.5-32 26.5-23.5 36-11.5 47.5 5.5l-1 3q38-9 51-9h761q74 0 114 56t18 130l-274 906q-36 119-71.5 153.5t-128.5 34.5h-869q-27 0-38 15-11 16-1 43 24 70 144 70h923q29 0 56-15.5t35-41.5l300-987q7-22 5-57 38 15 59 43zm-1064 2q-4 13 2 22.5t20 9.5h608q13 0 25.5-9.5t16.5-22.5l21-64q4-13-2-22.5t-20-9.5h-608q-13 0-25.5 9.5t-16.5 22.5zm-83 256q-4 13 2 22.5t20 9.5h608q13 0 25.5-9.5t16.5-22.5l21-64q4-13-2-22.5t-20-9.5h-608q-13 0-25.5 9.5t-16.5 22.5z'

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)