Skip to content
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

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

Closed
Hermeij opened this issue Feb 18, 2023 · 2 comments · Fixed by #6567
Closed

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

Hermeij opened this issue Feb 18, 2023 · 2 comments · Fixed by #6567
Labels
bug something broken

Comments

@Hermeij
Copy link

Hermeij commented Feb 18, 2023

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)
@Hermeij Hermeij changed the title [BUG] visible ='legendonly' doesn't work anymore in Scattermapbox visible ='legendonly' doesn't work anymore in Scattermapbox Feb 18, 2023
@alexcjohnson
Copy link
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

@alexcjohnson alexcjohnson transferred this issue from plotly/dash Mar 3, 2023
@Hermeij
Copy link
Author

Hermeij commented Mar 3, 2023

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
Labels
bug something broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants