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
Adding fig.update_layout(legend_groupclick="toggleitem") (as documented) to the grouped legend items example does not affect legend click behavior. With or without setting to "toggleitem", the whole group is toggled when clicking any item in the legend. Using plotly==5.4.0.
importplotly.graph_objectsasgofig=go.Figure()
fig.add_trace(
go.Scatter(
x=[1, 2, 3],
y=[2, 1, 3],
legendgroup="group", # this can be any string, not just "group"legendgrouptitle_text="First Group Title",
name="first legend group",
mode="markers",
marker=dict(color="Crimson", size=10),
)
)
fig.add_trace(
go.Scatter(
x=[1, 2, 3],
y=[2, 2, 2],
legendgroup="group",
name="first legend group - average",
mode="lines",
line=dict(color="Crimson"),
)
)
fig.add_trace(
go.Scatter(
x=[1, 2, 3],
y=[4, 9, 2],
legendgroup="group2",
legendgrouptitle_text="Second Group Title",
name="second legend group",
mode="markers",
marker=dict(color="MediumPurple", size=10),
)
)
fig.add_trace(
go.Scatter(
x=[1, 2, 3],
y=[5, 5, 5],
legendgroup="group2",
name="second legend group - average",
mode="lines",
line=dict(color="MediumPurple"),
)
)
# No effect from this linefig.update_layout(legend_groupclick="toggleitem")
@archmoj Pinging you since you merged this feature into plotly.js and might know. Could it be that this attribute is simply not passed from class Legend into plotly.js correctly?
This works for me... Can you tell us a bit about the environment in which you're running plotly? If it's VSCode, there are sometimes problems whereby the version of Plotly.js that VSCode loads isn't up to date with the one in Plotly.py. This sometimes affects other environments such as Streamlit as well.
(for reference, I'm running this in JupyterLab 3, and it's working there, because pip install plotly automatically installs the latest version of Plotly.js in an Lab extension)
I am indeed using VS Code. I guess I can just cross post this issue to vscode-jupyter and reference microsoft/vscode-jupyter#2648?
The odd thing is, they no longer specify the plotly.js version in package.json. If they download plotly.js on installation, does that mean reinstalling the extension might update plotly?
Exporting the figure to HTML and opening in the browser makes legend_groupclick="toggleitem" work as expected. I noticed however that clicking the group legend title does nothing now. Is this expected? I thought it would still toggle the whole group?
Please do let the VSCode folks know! We submit PRs to their repos but I'm not sure we're submitting them to the right places or when/where the updated JS versions are supposed to show up. We need VSCode users like you to let their team know there are issues :)
Yes, exporting to HTML almost always gets you the version of Plotly.js that you're expecting, and yes, clicking on the group title doesn't toggle the group today. We'd be happy to accept a PR that does this, and there's an issue open requesting it, it's just not something the plotly team has prioritized at the moment.
Activity
janosh commentedon Nov 26, 2021
@archmoj Pinging you since you merged this feature into plotly.js and might know. Could it be that this attribute is simply not passed from
class Legendinto plotly.js correctly?nicolaskruchten commentedon Nov 26, 2021
This works for me... Can you tell us a bit about the environment in which you're running
plotly? If it's VSCode, there are sometimes problems whereby the version of Plotly.js that VSCode loads isn't up to date with the one in Plotly.py. This sometimes affects other environments such as Streamlit as well.nicolaskruchten commentedon Nov 26, 2021
(for reference, I'm running this in JupyterLab 3, and it's working there, because
pip install plotlyautomatically installs the latest version of Plotly.js in an Lab extension)janosh commentedon Nov 26, 2021
I am indeed using VS Code. I guess I can just cross post this issue to
vscode-jupyterand reference microsoft/vscode-jupyter#2648?The odd thing is, they no longer specify the plotly.js version in
package.json. If they download plotly.js on installation, does that mean reinstalling the extension might update plotly?janosh commentedon Nov 26, 2021
Exporting the figure to HTML and opening in the browser makes
legend_groupclick="toggleitem"work as expected. I noticed however that clicking the group legend title does nothing now. Is this expected? I thought it would still toggle the whole group?nicolaskruchten commentedon Nov 26, 2021
Please do let the VSCode folks know! We submit PRs to their repos but I'm not sure we're submitting them to the right places or when/where the updated JS versions are supposed to show up. We need VSCode users like you to let their team know there are issues :)
Yes, exporting to HTML almost always gets you the version of Plotly.js that you're expecting, and yes, clicking on the group title doesn't toggle the group today. We'd be happy to accept a PR that does this, and there's an issue open requesting it, it's just not something the plotly team has prioritized at the moment.
janosh commentedon Nov 26, 2021
Thanks!