Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

dcc.Interval not working

I’ve noticed a weird behavior of dcc.Interval in my application. I want to use dcc.Interval to update a paragraph in my application but the callback seems to be called only once (I’m printing n_intervals). However if there’s an error in the callback, such as a reference to an unexisting variable, the callback gets called as it should. Here’s part of my code.

layout = html.Div([
    dcc.Link('Go to App 2', href='/apps/app2'),
                         interval=1*1000, n_intervals=0)
        ], className="six columns", id="objects"),
        html.Div([html.P("Empty")], className="six columns"),
    ], className="row"),
              html.Iframe(src="", width="560", height="315")], id="Ad")
], style = {'textAlign': 'center'})

    Output('objects', 'children'),
    [Input('interval-component', 'n_intervals')])
def timer(n):
    # print(asdlol) # if I enable this line the function is called periodically
    return [html.P("")]

The problem is that you are replacing the children of the objects div with html.P the first time the Interval fires…but the Interval is one of the children of the objects div.

So if there is an error in the callback function, the children are not replaced, which means the Interval still fires. If there is not an error, Interval will not exist anymore. You need to move the Interval outside of the children of the objects div.

1 Like

What if I need that the update will be executed on one of the children components?