Skip to content

legend_groupclick="toggleitem" not working #3488

Closed

Description

@janosh

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

Activity

  1. janosh commented on Nov 26, 2021

    @janosh
    ContributorAuthor

    @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?

  2. nicolaskruchten commented on Nov 26, 2021

    @nicolaskruchten
    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.

  3. nicolaskruchten commented on Nov 26, 2021

    @nicolaskruchten
    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)

  4. janosh commented on Nov 26, 2021

    @janosh
    ContributorAuthor

    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?

  5. janosh commented on Nov 26, 2021

    @janosh
    ContributorAuthor

    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?

  6. nicolaskruchten commented on Nov 26, 2021

    @nicolaskruchten
    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.

  7. janosh commented on Nov 26, 2021

    @janosh
    ContributorAuthor

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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