Hi,
I have a scatter plot like this, for which I have a multi dropdown input.
Everything loads fine initially, but then when I start to add further input values on the dropdown, the graph will only show the first N-1 text overlays when I have N inputs in the input box (like this - notice the text for Greece is not shown).
Any idea what could be causing it?
For reference, these are the snippets of code relevant:
def make_scatter_comp(in_df, var1, var2, x_log, y_log, names_list):
overlays = in_df['country'].apply(lambda x: x if x in names_list else '').values
fig = px.scatter(in_df, x=var1, y=var2, log_x=x_log, log_y=y_log, text=overlays,
title=data_labels[var1] + ' vs ' + data_labels[var2],
labels=data_labels,
color='continent', size="population", size_max=25,
color_discrete_map=cont_colours,
category_orders={'continent': cont_order},
template='plotly_white', hover_name='country')
fig.update_traces(marker=dict(line=dict(width=1, color='Gray')), textposition='top center')
fig.update_layout(font=dict(size=font_size, color='DarkSlateGray'), width=800, height=500)
...
dbc.Row([
dbc.Col([
dbc.Badge("(Cosmetic) Show text for:", color="secondary", className="mr-1"),
dbc.FormGroup([
dcc.Dropdown(
id='scatter_name_overlay',
options=[{'label': k, 'value': k} for k in np.sort(df.country.unique())],
value=['China'],
multi=True,
style={'width': '100%'}
)],
)], md=6
),
]),
...
@app.callback(
Output('scatter_one', 'figure'),
[Input('scatter_xvar', 'value'), Input('scatter_yvar', 'value'),
Input('scatter_x_log_radio', 'checked'), Input('scatter_y_log_radio', 'checked'),
Input('scatter_name_overlay', 'value')]
)
def update_scatter(var1, var2, x_log, y_log, names):
# if var1 != var2:
if type(names) == list:
names_list = names
else:
names_list = [names]
fig = make_scatter_comp(df, var1, var2, x_log, y_log, names_list)
return fig
Thanks!
Edit: When I look at the fig
object contemporaneously, the text item contains the correct data, so it is being passed on correctly…