0

I am trying to remove buttons from the modebar using config but it either returns an error or displays text in the console with no change to the plot itself:

myplot <- plot_ly(mtcars) %>% 
  add_markers(x = ~wt, y = ~mpg) %>%
  layout(
    xaxis = list(
      title = 'Weight in kilograms (kg)'
    ), 
    yaxis = list(
      title = 'Fuel efficiency (miles/gallon)'
    )
  )%>%
  config(
    displaylogo = FALSE, 
    collaborate = FALSE,
    modeBarButtonsToRemove = c(
      'sendDataToCloud', 'autoScale2d', 'resetScale2d', 'toggleSpikelines',
      'hoverClosestCartesian', 'hoverCompareCartesian',
      'zoom2d','pan2d','select2d','lasso2d','zoomIn2d','zoomOut2d'
    )
  )

modeBarButtonsToRemove is based on the plotly GitHub page.

I've also tried defining the plot first and then using config without any success:

myplot <- plot_ly() ...    
config(myplot, ...) 

For my actual use case, I will save the plots as html files using htmlwidgets::saveWidget(). In the above examples the modebar is visible in both the html files and also RStudio Viewer.

enter image description here

I've checked the following questions but the approach in the answers doesn't work either (same as my sample code):

  1. How can I customize the modebar in plotly (preferably in R)?
  2. How to custom or display modebar in plotly?
  3. How to disable the zoom of a plotly chart in R?

Session Info:

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] mailR_0.4.1       htmlwidgets_1.5.2 withr_2.3.0       rvest_0.3.6       xml2_1.3.2        httr_1.4.2       
 [7] jsonlite_1.7.1    plotly_4.9.2.1    ggplot2_3.3.2     lubridate_1.7.9   data.table_1.13.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5        pillar_1.4.6      compiler_4.0.3    plyr_1.8.6        R.methodsS3_1.8.1 R.utils_2.10.1   
 [7] tools_4.0.3       digest_0.6.27     lifecycle_0.2.0   tibble_3.0.4      gtable_0.3.0      viridisLite_0.3.0
[13] pkgconfig_2.0.3   rlang_0.4.8       rstudioapi_0.11   crosstalk_1.1.0.1 yaml_2.2.1        curl_4.3         
[19] rJava_0.9-13      stringr_1.4.0     dplyr_1.0.2       generics_0.0.2    vctrs_0.3.4       grid_4.0.3       
[25] tidyselect_1.1.0  glue_1.4.2        R6_2.4.1          processx_3.4.4    purrr_0.3.4       tidyr_1.1.2      
[31] magrittr_1.5      ps_1.4.0          scales_1.1.1      ellipsis_0.3.1    htmltools_0.5.0   colorspace_1.4-1 
[37] stringi_1.5.3     lazyeval_0.2.2    munsell_0.5.0     crayon_1.3.4      R.oo_1.24.0   
Ruben Helsloot
  • 12,582
  • 6
  • 26
  • 49
Gautam
  • 2,597
  • 1
  • 28
  • 51
  • Hm. Using plotly 4.9.2.1 your code runs fine on my machine. I get a plotly chart which shows only the "camera" in the modebar. – stefan Nov 24 '20 at 20:48
  • @stefan that's odd, I'm running the same version as well.. I'll add the version info to the question.. – Gautam Nov 24 '20 at 20:54
  • Hi Gautam. That's really odd. Same R version and almost all packages are the same versions as on my machine. Only difference is the locale which in my case is German. But quite sure that this isn't the issue. – stefan Nov 24 '20 at 21:17
  • Hi, I was able to get it working with my minimal example in base R (but not RStudio). The same approach didn't work with my actual example which has a lot of shapes, annotations etc. - I don't see the additional traces/features as a reason for this failing but worth a shot - I'll try to anonymize my data and share the actual plot code here. Also planning to try on a different device running MacOS Mojave to if that makes a difference. – Gautam Nov 25 '20 at 14:49

0 Answers0