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