Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

datepicker fires callbacks more than necessary #209

Closed

Description

@chriddyp

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)

Activity

  1. added a commit that references this issue on Jun 29, 2018
    1cc0315
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions