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

datepicker fires callbacks more than necessary #209

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

datepicker fires callbacks more than necessary #209

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

Comments

@chriddyp
Copy link
Member

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

No branches or pull requests

2 participants