dash>=2.12.0 caused regression in multiple legends (legend2, legend3, ...)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 24.4k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 13
Description
Multiple legends are great!
However, I have found an edge case where since dash=2.12.0 if legend isn't used then legend2, legend3 stop working.
Expected behaviour: when you click a legend on/off the plot turns on/off.
| dash version | worked ? |
|---|---|
| 2.11.0 | worked as expected ✔️ |
| 2.11.1 | worked as expected ✔️ |
| 2.12.0 | not working ❌ |
| 2.12.1 | not working ❌ |
As a workaround you can make certain that you always use legend.
Here is an example where legend is not used, but legend2 and legend3 are used, you will find that clicking the legends will not turn them on/off:
import dash
from dash import dcc, html
import numpy as np
import plotly.graph_objs as go
x = np.linspace(0.0, 20.0, 100)
# Make example traces
traces = []
# Ensure that "Plot1" is visiable
traces.append(go.Scatter(
x=np.full([1], np.nan),
y=np.full([1], np.nan),
xaxis='x',
yaxis='y',
))
traces.append(go.Scatter(
x=x,
y=x**2,
xaxis='x',
yaxis='y2',
name='y = x**2',
hoverinfo='skip',
legend='legend2'
))
traces.append(go.Scatter(
x=x,
y=x**3,
xaxis='x',
yaxis='y2',
name='y = x**3',
legend='legend2'
))
traces.append(go.Scatter(
x=x,
y=np.sin(x),
xaxis='x',
yaxis='y3',
name='y = sin(x)',
legend='legend3'
))
traces.append(go.Scatter(
x=x,
y=np.cos(x),
xaxis='x',
yaxis='y3',
name='y = cos(x)',
legend='legend3'
))
# Layout with multiple legends
layout = go.Layout(
xaxis=dict(
title='x',
),
yaxis=dict(
title='Plot 1',
domain=[0.0000, 0.32],
),
yaxis2=dict(
title='Plot 2',
domain=[0.34, 0.65]
),
yaxis3=dict(
title='Plot 3',
domain=[0.67, 1.0]
),
legend=dict(
x=0.99,
y=0.33,
xanchor='right',
yanchor='top',
visible=True
),
legend2=dict(
x=0.99,
y=0.66,
xanchor='right',
yanchor='top',
visible=True
),
legend3=dict(
x=0.99,
y=0.99,
xanchor='right',
yanchor='top',
visible=True
),
)
figure = go.Figure(
data=traces,
layout=layout
)
app = dash.Dash(__name__)
app.layout = html.Div(
children=[
html.H1(
children="when clicked, \"legends\" don't turn plots on/off"
),
dcc.Graph(
figure=figure
)
]
)
if __name__ == '__main__':
app.run_server(debug=True)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Dash example with dash 2.11.x and 2.12.x, focusing on traces assigned only to legend2 and legend3. Done means clicking entries in those legends toggles their plots as expected without requiring a legend entry.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100