Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬Register for the Oct 27 webinar.

Multiple intervals in Dash

Started using Dash recently and having a great experience with it.

However, I now want to have multiple interval components within a page and any examples I’ve found are using Event and State from dash.dependencies [1], which have apparently been removed from the library [2]. How can I do this with current versions of Dash?

Thanks!

[1] https://github.com/plotly/dash-recipes/blob/master/multiple-intervals.py
[2] Why can't I import the Event dash dependency?

Event was removed in favor just using Input which makes more sense to me. State is still there and very useful and serves a different purpose.

Here is the most simple example involving multiple intervals:

import dash
import dash_core_components as dcc
import dash_html_components as html


app = dash.Dash(__name__)
app.layout = html.Div([
    dcc.Interval(id='interval-1', interval=1000),
    dcc.Interval(id='interval-2', interval=3000),
    html.Div(id='out-1'),
    html.Div(id='out-2')
])


@app.callback(output=dash.dependencies.Output('out-1', 'children'),
              inputs=[dash.dependencies.Input('interval-1', 'n_intervals')])
def interval1(n_intervals):
    return n_intervals


@app.callback(output=dash.dependencies.Output('out-2', 'children'),
              inputs=[dash.dependencies.Input('interval-2', 'n_intervals')])
def interval2(n_intervals):
    return n_intervals


if __name__ == '__main__':
    app.run_server()

Ah, seems that naming the parameters with ‘output=’ and ‘inputs=’ is necessary and is what I was missing.

Much appreciation for the clean example :slight_smile: