I am playing with Plotly in order to learn to make interactive plots and dashboards but I have encountered a weird behaviour that I am not able to understand, regarding the functioning of the dropdown menu.
The plot is displayed correctly, along with the button. Clicking in one of options effectively changes the plot content, but it comes with a caveat, the range is reset to the default of the dataset. I simplified the code to the minimal expression, as an example.
from plotly.subplots import make_subplots
buttons = [ dict( method='update', label='b1', visible=True, args=[{'y':[[1,2,3]], 'type':'scatter'}] ),
dict( method='update', label='b2', visible=True, args=[{'y':[[30,20,10]],'type':'scatter'}] )]
fig = make_subplots()
fig.add_scatter(x=[2,4,6], y=[1,2,3])
.update_xaxes(range=[-10, 10])
.update_layout(updatemenus=[{'buttons':buttons}])
Executing this piece of code returns a plot with the x-axis range in [-10,10] (correct). However, when selecting any of the dropdown options, the x-range reverts to [2,6] (incorrect), the basic range of the dataset.
I believe I am doing something wrong with the button/layout update, since I cannot change any other attribute as the color either, (I tried, for example, adding line_color : 'red'
to the args list, with no effect), so I am a bit lost.
Do you have any idea what I am doing wrong?
question from:
https://stackoverflow.com/questions/65516719/why-clicking-on-dropdown-menu-option-resets-the-x-range