Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly: How to change the default mode bar button?

Tags:

r

config

plotly

I am generating plotly graphics and using shinyapps to publish COVID data from my country.

But when I generate the plot the default modebar button is the "zoom" function and it makes complicated its use on a smartphone:

enter image description here

I need the "Pan" function is the default button but I could find the solution.

enter image description here

Thanks in advance.

like image 250
Ernesto Riveros Barrientos Avatar asked Aug 16 '26 23:08

Ernesto Riveros Barrientos


1 Answers

Just include:

fig <- fig %>% layout(dragmode='pan')

This will change your default activated menu option from...

enter image description here

... to:

enter image description here

Complete code:

x <- c(1:100)
random_y <- rnorm(100, mean = 0)
data <- data.frame(x, random_y)

fig <- plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines')

fig <- fig %>% layout(dragmode='pan')
fig

I hope this is what you were looking for! Don't hesitate to let me know if not.

like image 97
vestland Avatar answered Aug 19 '26 18:08

vestland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!