You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's not a bug, but I wouldn't say it's intuitive for R users, either. layout.updatemenus, plotlyProxy(), and the like more closely resemble the plotly.js side of things than they do the handy abstractions you find in plot_ly(). In your case, you left off the optional third argument inside of the lists you gave to args. That argument specifies which trace(s) you want your button to update, and it updates all of them if the argument is left off.
What's happening here isn't that the color is being stripped away, it's that all the y values for each trace are being updated to match that of the first trace; since the x values already matched each other, this stacks each trace one on top of the other, and the extra y values you gave aren't plotted since they don't have corresponding x values. The code here has what I think was your expected behavior:
In that example, I commented what the code would be if I hardcoded the new y values, but the uncommented version is more robust (though less straightforward). If you're looking for an easier way to do this, I have an old PR for a helper function called plotly_merge() that would do most of the heavy lifting for you. Here's an example of what it would look like:
list(
'NO<sub>x</sub>' = dat |>
plot_ly(x = ~date, y = ~nox) |>
add_lines(color = ~site),
'NO<sub>10</sub>' = dat |>
plot_ly(x = ~date, y = ~pm10) |>
add_lines(color = ~site)
) |>
plotly_merge(type = 'buttons', y = 0.8)
I would imagine that clicking the "NOx" button would do effectively nothing, but instead it seems to strip away the
color
feature of the plot.Before clicking:
After clicking:
Am I doing something wrong, or is this a bug?
The text was updated successfully, but these errors were encountered: