When you initialize the traces, you need to have all the keys defined. In this case, a scatter plot needs both x
and y
defined.
import dash
from dash.dependencies import Input, Output, State
import dash_html_components as html
import dash_core_components as dcc
import random
app = dash.Dash(__name__)
app.scripts.config.serve_locally = True
app.css.config.serve_locally = True
app.layout = html.Div([
html.Div([
dcc.Graph(
id='graph-extendable',
figure={'layout': {'title': 'Random title',
'barmode': 'overlay'},
'data': [{'x': [], 'y': []},
{'x': [], 'y': []},
{'x': [], 'y': []},
{'x': [], 'y': []},
{'x': [], 'y': []},
{'x': [], 'y': []},
{'x': [], 'y': []},
{'x': [], 'y': []},
{'x': [], 'y': []},
{'x': [], 'y': []},
{'x': [], 'y': []},
{'x': [], 'y': []},
{'x': [], 'y': []},
{'x': [], 'y': []},
{'x': [], 'y': []}, ]
}
),
]),
dcc.Interval(
id='interval-graph-update',
interval=1000,
n_intervals=0),
])
@app.callback(Output('graph-extendable', 'extendData'),
[Input('interval-graph-update', 'n_intervals')]
)
def create_then_extend_single_trace(n_intervals):
return (dict(x=[
[n_intervals],
[n_intervals]
],
y=[
[n_intervals],
[n_intervals**2]
]
),
[0, 4]
)
if __name__ == '__main__':
app.run_server(debug=True)
For future reference, check the browser debug console; the Plotly.js library has some exception handling which can point you to errors as it relates to dash components that don’t run.