Skip to content

legend_groupclick="toggleitem" not working #3488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
janosh opened this issue Nov 25, 2021 · 7 comments
Closed

legend_groupclick="toggleitem" not working #3488

janosh opened this issue Nov 25, 2021 · 7 comments

Comments

@janosh
Copy link
Contributor

janosh commented Nov 25, 2021

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.

import plotly.graph_objects as go


fig = 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 line
fig.update_layout(legend_groupclick="toggleitem")
@janosh
Copy link
Contributor Author

janosh commented 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 Legend into plotly.js correctly?

@nicolaskruchten
Copy link
Contributor

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
Copy link
Contributor

(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)

@janosh
Copy link
Contributor Author

janosh commented Nov 26, 2021

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?

@janosh
Copy link
Contributor Author

janosh commented 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
Copy link
Contributor

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
Copy link
Contributor Author

janosh commented Nov 26, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants