2023-02-17T23:00:00Z
I recently installed a new Anaconda/Spyder environment with:
python version: 3.19.13
plotly version : 5.9.0
dash version: 2.8.0
Sinds then I have a problem with the funcionality of visible = âlegendonlyâ in Scattermapbox.
When I add a trace with âvisible=Trueâ set, everything works fine. But when I add a trace with visible=âlegendonlyâ the legenditem is added to the legend but it doesnât show up the trace when the legenditem is activated.
-- coding: utf-8 --
ââ"
Created on Sat Feb 18 09:23:57 2023
@author: herma
ââ"
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)
fig1.add_traces(go.Scattermapbox(
lat = lat1_coord,
lon = lon1_coord,
mode=âlinesâ,
line = dict(
color = âredâ,
width = 2),
visible =âlegendonlyâ
)
)
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)