@@ -57,38 +57,48 @@ rangeslider <- function(p, ...) {
57
57
# ' @param p a plotly object
58
58
# ' @param ... these arguments are documented at
59
59
# ' \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?
60
62
# ' @author Carson Sievert
61
63
# ' @export
62
- # ' @examples \dontrun{
63
- # ' config(plot_ly(), displaylogo = FALSE)
64
- # ' }
64
+ # ' @examples
65
+ # '
66
+ # ' config(plot_ly(), displaylogo = FALSE, collaborate = FALSE)
67
+ # '
65
68
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
69
72
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())
74
73
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
+ }
84
95
85
96
# ensure array
86
97
if (length(p $ x $ config [[" modeBarButtonsToRemove" ]]) == 1 ) {
87
98
p $ x $ config [[" modeBarButtonsToRemove" ]] <- list (p $ x $ config [[" modeBarButtonsToRemove" ]])
88
99
}
89
100
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 (... ))
93
103
p
94
104
}
0 commit comments