Skip to content

Toggle button works with delay - bug in args2 in updatemenus / buttons #3471

@simotrone

Description

@simotrone

Hello,
I am using the updatemenus buttons and I found a bug in args2 option behavior - if I understood the feature from doc.

The issue is that the first click on the toggle button doesn't work.
From the second click, everything works as it should (on/off of the red vertical line).

import numpy as np
import plotly.graph_objects as go

data = dict(
    x = np.random.normal(2,0.4,400),
    y = np.random.normal(2,0.4,400)
)

scat = go.Scatter(
    x=data['x'],
    y=data['y'],
    mode="markers"
)
shape = dict(
    type='line',
    line=dict(color='red'),
    xref='x',
    x0=data['x'][5],
    x1=data['x'][5],
    yref='y domain',
    y0=0,
    y1=1
)
buttons = dict(
    type='buttons',
    buttons=[
        dict(
            label='Toggle',
            method='relayout',
            args=['shapes', [shape]],
            args2=['shapes', []]
        )
    ]
)
fig = go.Figure()
fig.add_trace(scat)
fig.update_layout(updatemenus=[buttons])
fig.show()

^^^
[edit] This is what I want. And it doesn't work well because it seems "forget" the first click on the button.

.
.
What follows are more information for dev about weird behaviours of buttons array:

As a bonus point, I noticed that if I add a button BEFORE the toggle button, the toggle button will work as expected.

buttons = dict(
    type='buttons',
    buttons=[
        dict(label='On',  method='relayout', args=['shapes', [shape]]),
        dict(label='Toggle', method='relayout', args=['shapes', [shape]], args2=['shapes', []] )
    ]
)

but if I put the code of the other button AFTER the toggle button ,the toggle button continues to have delay when clicked.

buttons = dict(
    type='buttons',
    buttons=[
        dict(label='Toggle', method='relayout', args=['shapes', [shape]], args2=['shapes', []] ),
        dict(label='On',  method='relayout', args=['shapes', [shape]])
    ]
)

I don't think this is expected.
I am using the 5.3.1 version and the bug is there on|offline.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions