Hi everyone, I’ve made another dashboard for Covid19 in Italy, but with region selectable with a dropdown.
For the styling I’m using dash-bootstrap-components, but my dashboard layout behaves in a strange way.
If I open my browser console, I get the error of the title of this post, and in debug mode I get this other error “Warning: Cannot update a component from inside the function body of a different component.”.
Practically through a callback associated with a function for each chart, I update the data based on the region selected in the dropdown.
But in some regions, the plots are missing…
You can see my test dashboard here.
And I post also two pieces of code:
dbc.Row( # andamento contagi
dbc.Col(
dcc.Graph(
id='andamento-contagi',
figure={},
config=chart_config
)
, width=12)
),
and the relative callback:
@app.callback(
Output('andamento-contagi', 'figure'),
[Input('region_select', 'value')])
def update_andamento_contagi(regione):
reg_df = df.loc[df['denominazione_regione'] == regione]
local_df = calculate_data(reg_df.copy())
figure = {
'data': [
{'x': local_df['data'], 'y': local_df['nuovi_positivi'], 'type': 'bar', 'name': 'Nuovi Casi'},
{'x': local_df['data'], 'y': local_df['nuovi_positivi_avg'], 'type': 'scatter',
'line': dict(color='orange'),
'name': 'Media 7 giorni'}
],
'layout': {
'title': 'Andamento dei contagi',
'xaxis': dict(
rangeselector=dict(buttons=slider_button),
rangeslider=dict(visible=False),
type='date'
)
}
}
return figure
The code for the other plots is similar.