Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Can't dynamically update max_intervals? #266

Closed
chriddyp opened this issue Aug 16, 2018 · 0 comments · Fixed by #278
Closed

Can't dynamically update max_intervals? #266

chriddyp opened this issue Aug 16, 2018 · 0 comments · Fixed by #278

Comments

@chriddyp
Copy link
Member

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging a pull request may close this issue.

2 participants