Skip to content

visible ='legendonly' doesn't work anymore in Scattermapbox #6508

Closed
@Hermeij

Description

@Hermeij

Describe your context
I installed a complete new Anaconda/Spyder environment on Windows 10. After that visible='legendonly' doesn't work anymore.

  • replace the result of pip list | grep dash below
dash                                        2.8.0              pyhd8ed1ab_0    conda-forge
dash-bootstrap-components 1.3.1              pyhd8ed1ab_0    conda-forge
plotly                                      5.9.0              py39haa95532_0
python                                    3.9.13            h6244533_1
  • if frontend related, tell us your Browser, Version and OS

    • OS: [Windows 10]
    • Browser [chrome, edge]
    • Version [chrome 110.0.5481.104 (Officiële build) (64-bits), edge Versie 110.0.1587.46 (Officiële build) (64-bits)],

Describe the bug

The visible='legendonly' doesn't work anymore in Scatermapbox.
When adding a trace with a visible value 'legendonly' , the trace is added to the legend. However the trace doesn't appear when the legend item is activated. Also when there are multiple traces added with one trace visible='legendonly' and the other traces visible=True, then you can only turn on/off the visible=True traces when the visible='legendonly' trace is de-activated.

Expected behavior

visible='legendonly' will add a trace to the legend. After that you will be able to turn on/off the trace.

Screenshots

If applicable, add screenshots or screen recording to help explain your problem.

Example

from plotly import graph_objs as go
import dash
from dash import dcc
from dash import html

lat_center = 52.1009166
lon_center = 5.6462914
zoom = 8

lat1_coord = [52.0, 52.2]
lon1_coord = [5.6, 5.7]

lat2_coord = [51.9, 52.0]
lon2_coord = [5.6, 5.7]

fig1 = go.Figure()
fig1.update_layout(
    mapbox = dict(
        style = "open-street-map",
        zoom = zoom,
        center = dict(
            lat = lat_center,
            lon = lon_center
            )
        ),
    showlegend = True)

#Trace visible='legendonly'
fig1.add_traces(
    go.Scattermapbox(
        lat = lat1_coord,
        lon = lon1_coord,
        mode='lines',
        line = dict(
            color = 'red',
            width = 2),
        visible ='legendonly'
        )
    )

#Trace visible=True
fig1.add_traces(
    go.Scattermapbox(
        lat = lat2_coord,
        lon = lon2_coord,
        mode =' lines',
        line = dict(
            color = 'blue',
            width = 2),
        visible = True
        )
    )

app = dash.Dash(__name__)

app.layout = html.Div(
    dcc.Graph(
            id = 'map_tiles',
            figure = fig1
        )
    )

host = "127.0.0.1"
port = "8050"
DEBUG = True

if __name__ == "__main__":
    app.run_server(host=host, port=port, debug = DEBUG,use_reloader=False)

Activity

changed the title [-][BUG] visible ='legendonly' doesn't work anymore in Scattermapbox[/-] [+]visible ='legendonly' doesn't work anymore in Scattermapbox[/+] on Feb 18, 2023
alexcjohnson

alexcjohnson commented on Mar 3, 2023

@alexcjohnson
Collaborator

Thanks @Hermeij - this is a problem in plotly.js, I will move the issue over there. Both parts of the problem you identified are visible in this codepen: https://codepen.io/alexcjohnson/pen/BaORKpj?editors=0010: whenever the map tried to render with the blue line displayed it throws the error: Uncaught (in promise) Error: There is already a source with this ID

transferred this issue fromplotly/dashon Mar 3, 2023
Hermeij

Hermeij commented on Mar 3, 2023

@Hermeij
Author

Hi @alexcjohnson,
Thank you for your response and action. I hope there will be a solution soon.

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

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alexcjohnson@Hermeij

      Issue actions

        visible ='legendonly' doesn't work anymore in Scattermapbox · Issue #6508 · plotly/plotly.js