Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Can't dynamically update max_intervals? #266

Closed

Description

@chriddyp

I'm trying to use dcc.Interval max_interval property to create "start" and "stop" buttons that turn off the dcc.Interval. It seems like updating max_interval doesn't end up restarting the interval.

Here's a simple reproducable example:

import dash
from dash.dependencies import Input, Output
import dash_html_components as html
import dash_core_components as dcc

app = dash.Dash()

app.layout = html.Div([
    dcc.Interval(
        id='interval',
        interval=100,
        n_intervals=0,
        max_intervals=0
    ),

    html.Button('Start', id='start', n_clicks_timestamp=-1),
    html.Button('Stop', id='stop', n_clicks_timestamp=-1),

    html.Div(id='output')

])


@app.callback(
    Output('interval', 'max_intervals'),
    [Input('start', 'n_clicks_timestamp'),
     Input('stop', 'n_clicks_timestamp')])
def start_stop(start, stop):
    if start > stop:
        print('Returning -1')
        return -1
    else:
        print('Returning 0')
        return 0


@app.callback(Output('output', 'children'), [Input('interval', 'n_intervals')])
def display_data(n_intervals):
    return 'Updated {}'.format(n_intervals)


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

@valentijnnieman - Could you take a look? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions