Hi everybody!
I faced an inconsistent error while updating dcc.Graph with px.scatter object via callback.
It happens right after I run my app and push the button triggering the dcc.Graph update so that it is obviously connected to scatter plot initialization. But the error occurs randomly, sometimes my app works regularly.
Once I face the error, the app goes OK then.
It really seems to be similar to this case:
My callback code…
@app.callback(
Output('Scatter_plot', 'figure'),
Output('Histogram', 'figure'),
Output('Bar_chart', 'figure'),
Input({'type': 'column_name_buttons', 'index': ALL}, 'n_clicks'),
State('Histogram_norm_type', 'value'),
State('Time_checklist', 'value'),
State('Date_checkbox', 'value'),
State('Date_picker_range', 'start_date'),
State('Date_picker_range', 'end_date'),
prevent_initial_call=True
)
def update_plots(*input_parameters):
changed_id = dash.callback_context.triggered[0]['prop_id'].split('","type"')[0].split('"index":"')[1]
dff, date_axis = aggregate_by_date_time(input_parameters[-1],
input_parameters[-2],
input_parameters[-3],
input_parameters[-4]
)
xaxis = date_axis if date_axis is None else dff['Date_Time']
fig_scatter = px.scatter(data_frame=dff, x=xaxis, y=changed_id, color='ErrorMessage')
fig_scatter.update_layout(paper_bgcolor='#f0f8ff', plot_bgcolor='#f0f8ff')
fig_hist = px.histogram()
if input_parameters[-5] == 'count': # index [-5] is a 'Histogram_norm_type' - 'value'
fig_hist = px.histogram(dff, y=changed_id, x=xaxis, color='ErrorMessage', marginal='box',
histfunc='count')
elif input_parameters[-5] == 'percent': # index [-5] is a 'Histogram_norm_type' - 'value'
fig_hist = px.histogram(dff, y=changed_id, x=xaxis, color='ErrorMessage', marginal='box',
histfunc='count', histnorm='percent')
fig_hist.update_layout(paper_bgcolor='#f0f8ff', plot_bgcolor='#f0f8ff')
fig_hist.update_traces(opacity=0.72)
fig_bar = px.histogram(dff, x='ErrorMessage', histfunc='count', color='ErrorMessage')
fig_bar.update_layout(paper_bgcolor='#f0f8ff', plot_bgcolor='#f0f8ff', barmode='stack')
fig_bar.update_traces(opacity=0.72)
return fig_scatter, fig_hist, fig_bar,
Error message:
Traceback (most recent call last):
File “/Users/igorderiabin/Yandex.Disk.localized/HFU/BCM/Thesis/PREFERML_test/app.py”, line 426, in update_plots
fig_scatter = px.scatter(data_frame=dff, x=xaxis, y=changed_id, color=‘ErrorMessage’)
File “/Users/igorderiabin/Yandex.Disk.localized/HFU/BCM/Thesis/PREFERML_test/venv/lib/python3.7/site-packages/plotly/express/_chart_types.py”, line 64, in scatter
return make_figure(args=locals(), constructor=go.Scatter)
File “/Users/igorderiabin/Yandex.Disk.localized/HFU/BCM/Thesis/PREFERML_test/venv/lib/python3.7/site-packages/plotly/express/_core.py”, line 1877, in make_figure
apply_default_cascade(args)
File “/Users/igorderiabin/Yandex.Disk.localized/HFU/BCM/Thesis/PREFERML_test/venv/lib/python3.7/site-packages/plotly/express/_core.py”, line 945, in apply_default_cascade
scatter.marker.symbol for scatter in args[“template”].data.scatter
File “/Users/igorderiabin/Yandex.Disk.localized/HFU/BCM/Thesis/PREFERML_test/venv/lib/python3.7/site-packages/plotly/express/_core.py”, line 945, in
scatter.marker.symbol for scatter in args[“template”].data.scatter
File “/Users/igorderiabin/Yandex.Disk.localized/HFU/BCM/Thesis/PREFERML_test/venv/lib/python3.7/site-packages/plotly/graph_objs/scatter/_marker.py”, line 1042, in symbol
return self[“symbol”]
File “/Users/igorderiabin/Yandex.Disk.localized/HFU/BCM/Thesis/PREFERML_test/venv/lib/python3.7/site-packages/plotly/basedatatypes.py”, line 4693, in getitem
elif self._props is not None and prop in self._props:
File “/Users/igorderiabin/Yandex.Disk.localized/HFU/BCM/Thesis/PREFERML_test/venv/lib/python3.7/site-packages/plotly/basedatatypes.py”, line 4388, in _props
return self.parent._get_child_props(self)
File “/Users/igorderiabin/Yandex.Disk.localized/HFU/BCM/Thesis/PREFERML_test/venv/lib/python3.7/site-packages/plotly/basedatatypes.py”, line 4402, in _get_child_props
if self._props is None:
File “/Users/igorderiabin/Yandex.Disk.localized/HFU/BCM/Thesis/PREFERML_test/venv/lib/python3.7/site-packages/plotly/basedatatypes.py”, line 4388, in _props
return self.parent._get_child_props(self)
File “/Users/igorderiabin/Yandex.Disk.localized/HFU/BCM/Thesis/PREFERML_test/venv/lib/python3.7/site-packages/plotly/basedatatypes.py”, line 4422, in _get_child_props
child_ind = BaseFigure._index_is(children, child)
File “/Users/igorderiabin/Yandex.Disk.localized/HFU/BCM/Thesis/PREFERML_test/venv/lib/python3.7/site-packages/plotly/basedatatypes.py”, line 3952, in _index_is
raise ValueError(“Invalid value”)
ValueError: Invalid value
P.S. The error still occurs even if I use plotly.express.scatter() with no arguments, like:
px.scatter() instead of px.scatter(data_frame=dff, x=xaxis, y=changed_id, color=‘ErrorMessage’)