I’m trying to include two separate toggles that alters the color and symbol for a scattermapbox. The color toggle works fine and while the symbol toggle works, it drops the color.
I want to be able to turn on the symbol AND the color at the same time. Is it possible to do so?
Note: It needs to be scattermapbox
<code>import dash
from dash import Dash, dcc, html, Input, Output
import plotly.express as px
import pandas as pd
import plotly.graph_objs as go
df = px.data.iris()
color_dict = {'versicolor': 'brown', 'setosa': 'orange', 'virginica': 'pink'}
symbol_dict = {'versicolor': 'star', 'setosa': 'circle', 'virginica': 'triangle'}
cmap = df["species"].map(color_dict)
smap = df["species"].map(symbol_dict)
app = dash.Dash(__name__)
app.layout = html.Div(
[
html.P("Toggle for the color"),
dcc.Checklist(
id="color_toggle",
options=[{"label": "", "value": True}],
value=[],
inline=True
),
html.P("Toggle for the symbol"),
dcc.Checklist(
id="symbol_toggle",
options=[{"label": "", "value": True}],
value=[],
inline=True
),
html.Div(
dcc.Graph(id="chart"),
),
]
)
@app.callback(
Output("chart", "figure"),
[Input("color_toggle", "value"),
Input("symbol_toggle", "value")
]
)
def update_fig(cmap_on, smap_on):
fig = go.Figure(go.Scattermapbox(
lat=df['sepal_width'],
lon=df['sepal_length'],
mode='markers',
marker=dict(color = cmap if cmap_on else None,
symbol = smap if smap_on else None,
)
)
)
fig.update_layout(height = 750,
mapbox=dict(
accesstoken=mapboxtoken,
style='light',
))
fig.update_mapboxes(zoom = 4)
return fig
if __name__ == "__main__":
app.run_server(debug=True)
</code>
<code>import dash
from dash import Dash, dcc, html, Input, Output
import plotly.express as px
import pandas as pd
import plotly.graph_objs as go
df = px.data.iris()
color_dict = {'versicolor': 'brown', 'setosa': 'orange', 'virginica': 'pink'}
symbol_dict = {'versicolor': 'star', 'setosa': 'circle', 'virginica': 'triangle'}
cmap = df["species"].map(color_dict)
smap = df["species"].map(symbol_dict)
app = dash.Dash(__name__)
app.layout = html.Div(
[
html.P("Toggle for the color"),
dcc.Checklist(
id="color_toggle",
options=[{"label": "", "value": True}],
value=[],
inline=True
),
html.P("Toggle for the symbol"),
dcc.Checklist(
id="symbol_toggle",
options=[{"label": "", "value": True}],
value=[],
inline=True
),
html.Div(
dcc.Graph(id="chart"),
),
]
)
@app.callback(
Output("chart", "figure"),
[Input("color_toggle", "value"),
Input("symbol_toggle", "value")
]
)
def update_fig(cmap_on, smap_on):
fig = go.Figure(go.Scattermapbox(
lat=df['sepal_width'],
lon=df['sepal_length'],
mode='markers',
marker=dict(color = cmap if cmap_on else None,
symbol = smap if smap_on else None,
)
)
)
fig.update_layout(height = 750,
mapbox=dict(
accesstoken=mapboxtoken,
style='light',
))
fig.update_mapboxes(zoom = 4)
return fig
if __name__ == "__main__":
app.run_server(debug=True)
</code>
import dash
from dash import Dash, dcc, html, Input, Output
import plotly.express as px
import pandas as pd
import plotly.graph_objs as go
df = px.data.iris()
color_dict = {'versicolor': 'brown', 'setosa': 'orange', 'virginica': 'pink'}
symbol_dict = {'versicolor': 'star', 'setosa': 'circle', 'virginica': 'triangle'}
cmap = df["species"].map(color_dict)
smap = df["species"].map(symbol_dict)
app = dash.Dash(__name__)
app.layout = html.Div(
[
html.P("Toggle for the color"),
dcc.Checklist(
id="color_toggle",
options=[{"label": "", "value": True}],
value=[],
inline=True
),
html.P("Toggle for the symbol"),
dcc.Checklist(
id="symbol_toggle",
options=[{"label": "", "value": True}],
value=[],
inline=True
),
html.Div(
dcc.Graph(id="chart"),
),
]
)
@app.callback(
Output("chart", "figure"),
[Input("color_toggle", "value"),
Input("symbol_toggle", "value")
]
)
def update_fig(cmap_on, smap_on):
fig = go.Figure(go.Scattermapbox(
lat=df['sepal_width'],
lon=df['sepal_length'],
mode='markers',
marker=dict(color = cmap if cmap_on else None,
symbol = smap if smap_on else None,
)
)
)
fig.update_layout(height = 750,
mapbox=dict(
accesstoken=mapboxtoken,
style='light',
))
fig.update_mapboxes(zoom = 4)
return fig
if __name__ == "__main__":
app.run_server(debug=True)