After looking around I can't seem to find a way to disable dragging of y axis in pan mode, while also allowing to zoom both axes.
Anyone figured this one out yet ?
The data is positional positive integer count data, so I want to keep zoom on Y as a normalization option for regions with large extremes.
I checked through r plotly API tutorial and issues on Github, I also checked through the code of r plotly and Google. All I could find was this link to plotly.js, discussing it: https://github.com/plotly/plotly.js/issues/887 Does this mean there is no workaround ?
If you combine the ability to identify whether you're panning or zooming, along with
relayout, you can create this effect.I created some arbitrary data to demonstrate how this works. I used the function
htmlwidgets::onRenderto add the Plotly event listener.In my example, I've preset the plot to the
dragmode'pan'. I've also changed the y-axis to be fixed in place. To zoom or changing back to panning, you will use the mode bar.The
onRenderfunction creates an event listener forplotly_relayout. When you select an item in themodebar, you're causing arelayoutevent. Additionally, when you change whether the y-axis is fixed in place or not, that is also arelayoutevent.To distinguish whether this is a
relayoutevent that is triggered by a selection in themodebar, I usedif(...== "dragmode"If this is a
modebartriggered event, then the fixed range status is changed based on whether you are panning or zooming.I wanted to point out that if you pan after you've zoomed, you restrict the y-axis to whatever is shown at that point in time. To fully reset the plot, you need to select zoom in the mode bar (even if you don't plan on using it) to change the y-axis back to an unfixed range.
After panning:
After selecting zoom, home, than selecting a zoom range (dragging on the plot):