Black Lives Matter. Please consider donating to Black Girls Code today.
Dash Enterprise delivers an incredible 21x cost savings 💸Download the e-book!

One plot, two dropdown menus, two y-axis, update the data for the y-axis, Is it POSSIBLE?

I want to draw a plot with two different y-axis. I decide to use two y-axis because of the scale of the data, the scale is so different between the two data vectors I want to plot and the idea is to have a single plot with two different yaxis and two different dropdown lists, so I can update the data for each of the y-axis, so far I’ve been able to update the data for a single single y-axis but I’m unable to update the data for the second y-axis. Is my plan possible? Am I crazy? I appreciate any help.

I write below the following toy code that I am using to explore my idea. Thanks! (and I’m sorry for my English, it’s not my first lenguage).

Generate random data

pp = runif(200)
qq = runif(200)
rr = runif(200)

List with second y-axis properties

y2 <- list(
overlaying = “y”,
side = “right”,
title = “yaxis2”
)

Toy plot

p <- plot_ly()%>%
add_lines( x = pp, y = qq, mode = “markers”, name = “A”)%>%
add_lines( x = pp, y = rr, mode = “markers”, name = “B”, yaxis = ‘yaxis2’)%>% # decirle que esto va en el yaxis2
layout(
xaxis = list(domain = c(0.1, 1)),
yaxis = list(title = “y”),
yaxis2 = y2,
updatemenus = list(
list(
y = 0.7,
buttons = list(
list(method = “restyle”,
args = list(“y”, list(df$qq)), # So far I can update data for for my first y-axis
label = “Show A”),
list(method = “update”,
args = list(“y”, list(df$pp)), # So far I can update data for for my first y-axis
label = “Show B”))),
list(
y = 0.5,
buttons = list(
list(method = “restyle”,
args = list(“yaxis2”, list(df$rr)), # But not for the second y-axis, how can I update the data for the second y-axis?
label = “Show A”),
list(method = “update”,
args = list(“yaxis2”, list(df$pp)), # But not for the second y-axis, how can I update the data for the second y-axis?
label = “Show B”))))
)