4

I didn't find an argument to disable the zoom mode of the mouse cursor on a plotly graph. This is bad because when you drag your fingers across your phone, the zoom increases. Taking advantage of the question, I would like to remove all the buttons from the plotly and leave only the button to download the image.

Igor Cobelo
  • 419
  • 3
  • 12

1 Answers1

14

There is a lot you can do! The button line in plotly is called "modebar" and you can remove it completely, or remove specific buttons from it:

plot_ly() %>%
  config(modeBarButtonsToRemove = c("zoomIn2d", "zoomOut2d"))

See more details in the book Interactive web-based data visualization with R, plotly, and shiny.

(Documentation is unfortunately very brief.)

If you want not only to disable buttons, but also to disable zooming completely, use layout() with xaxis and yaxis arguments to fix the axis range by fixedrange settings (note it has to be a list):

library(plotly)

plot_ly(x = 1:10,y = 1:10) %>%
    layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange = TRUE))

See xaxis and yaxis documentation for zooming.

  • Petr, this only omits the buttons, but the zoom mode on the cursor continues ... – Igor Cobelo Jul 11 '20 at 19:25
  • 3
    @IgorCobelo Hi Igor, oh, sorry, my mistake. I have updated the answer with a solution to disable zooming, see [xaxis](https://plotly.com/r/reference/#layout-xaxis-fixedrange) and [yaxis](https://plotly.com/r/reference/#layout-yaxis-fixedrange)... hope it helps this time :-) –  Jul 11 '20 at 20:42
  • 1
    It also works with `ggplotly(p) |> layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange = TRUE))` :) – bathyscapher Dec 01 '21 at 17:01