Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't dynamically update `max_intervals`? #266

Closed
chriddyp opened this issue Aug 16, 2018 · 0 comments

Comments

2 participants
@chriddyp
Copy link
Member

commented Aug 16, 2018

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
You can’t perform that action at this time.