Dcc.interval reset the layout at each "n_intervals"

Hey everyone,

I can’t figure out why adding a callback (with a dcc.Interval as input) reset the all layout to its initial state.
any one having face the same issue ?

import dash
import dash_core_components as dcc
import dash_html_components as html

from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate

app = dash.Dash(__name__)

server = app.server

app.layout = html.Div([

    dcc.Dropdown(
        options=[
            {'label': 'choice 1', 'value': 'choice1'},
            {'label': 'choice 2', 'value': 'choice2'}
        ],
        style={'height': '40px',
               'width': '280px'}
    ),

    dcc.Interval(id='interval', interval=3 * 1000, n_intervals=0),

    html.Button('run', id='button1'),

    html.Div(id='yala_container')

])


@app.callback(Output('yala_container', 'children'),
              [Input('button1', 'n_clicks'),
               Input('interval', 'n_intervals')])
def call_launch_logs(n_clicks, n_intervals):

    if n_clicks is None:
        raise PreventUpdate
    return html.Div('yala')


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

and here is a record of what’s going on…

here are the version of my packages:
dash==0.37.0
dash-core-components==0.43.1
dash-html-components==0.13.5
dash-renderer==0.18.0
dash-table==3.4.0

Your Dropdown component is not registered with any callback. Try hooking it up and see if that fixes it. There is a subtle gotcha that some components will break your app when present in the layout but not registered.

1 Like