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

datepicker fires callbacks more than necessary #209

Closed
chriddyp opened this issue Jun 7, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@chriddyp
Copy link
Member

commented Jun 7, 2018

setProps should only be called once when the property change, in onDatesChange it's being called multiple times

setProps({start_date: start_date.format('YYYY-MM-DD')});
} else {
newState.start_date = start_date;
}
if (setProps && end_date !== null) {
setProps({end_date: end_date.format('YYYY-MM-DD')});

reproducable example

import numpy as np
import pandas as pd
from datetime import datetime as dt
import pytz
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
from plotly import tools


app = dash.Dash()

CHOICES = [
    {'label': 1, 'value': 'Option 1'},
    {'label': 2, 'value': 'Option 2'}
]

app.layout = html.Div(children=[
    html.Div(
        dcc.DatePickerRange(
            id='my-date-picker-range',
            min_date_allowed=dt(2017, 10, 1),
            max_date_allowed=dt(2018, 8, 1),
            initial_visible_month=dt(2018, 3, 1),
            display_format='YYYY/MM/DD',
            start_date='2018-03-04',
            end_date='2018-03-06'
        ), style={'text-align': 'center'}
    ),

    html.Div(
        dcc.Dropdown(
            id='extruder-choice',
            options=CHOICES,
            value='Option 1'
        )
    ),
    html.Div(
        dcc.Graph(
            id='time-series-figure',
            config={'modeBarButtonsToRemove': ['sendDataToCloud']}
            ),
        style={
            'height': '1000px',
            }
    ),
])

i = 0
@app.callback(
    dash.dependencies.Output('time-series-figure', 'figure'),
    [dash.dependencies.Input('my-date-picker-range', 'start_date'),
    dash.dependencies.Input('my-date-picker-range', 'end_date'),
    dash.dependencies.Input('extruder-choice', 'value')]
)
def update_daterange(startdate, enddate, extruder):
    date_range = [startdate, enddate]
    global i
    i += 1
    print('{} - update_daterange called'.format(i))
    return {'data': [{'x': [1, 2, 3]}]}


if __name__ == '__main__':
    app.run_server(debug=True, port=8051)
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.