I’m trying to create multiple time-series line plots (with range slider) in Dash, and I’d like to be able to cross-filter on them. What’s the best way to do this? I want the other time-series plots to update when I drag and select a time range within a given plot. Naively I would expect a drag and select of a range to count as “selectedData”, but that fails to trigger the callback. clickData seems to work, but that’s not the desired behaviour I think for a time-series plot. Here’s my code so far. Any thoughts?
app = dash.Dash()
layout = dict(
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=1,
label='1m',
step='month',
stepmode='backward'),
dict(count=6,
label='6m',
step='month',
stepmode='backward'),
dict(step='all')
])
),
rangeslider=dict(),
type='date'
)
)
app.layout = html.Div([
dcc.Graph(id='metrics', figure={'data': [go.Scatter(
x=mdf['date'],
y=mdf['counts'])], 'layout': layout}),
dcc.Graph(id='metrics2', figure={'data': [go.Scatter(
x=mdf['date'],
y=mdf['uniqvisits'])], 'layout': layout})
])
@app.callback(
Output('metrics2', 'figure'),
[Input('metrics', 'selectedData')])
def display_selected_data(selectedData):
traces = [go.Scatter(
x=mdf['date'],
y=mdf['uniqvisits'])]
return {
'data': traces,
'layout': layout
}