dash-core-components icon indicating copy to clipboard operation
dash-core-components copied to clipboard

Unable to specify defaults for individual date pickers in DatePickerRange

Open davenewham opened this issue 5 years ago • 6 comments

Currently, my date range is fed an existing date range based on the data being displayed, however, there is no way to individually set the initial visible month for each of the date pickers. Especially if the data displayed is historical this is problematic as you have to set either the start date / end date as the initial visible month

ezgif com-video-to-gif

To replicate this:

dcc.DatePickerRange(
    id='date-picker-range',
    start_date = dt(2017, 1, 31),
    end_date = dt(2018, 3, 21),
    min_date_allowed = dt(2017, 1, 31),
    max_date_allowed = dt(2018, 3, 21),
    initial_visible_month =  start_date=dt(2017, 1, 31)
)

davenewham avatar Oct 10 '19 08:10 davenewham

I'm not sure I understand, the code above gives an error because you cannot assign a variable when setting the value of a keyword argument. What if you define a variable which you use both for the value of start_date and initial_visible_month?

emmanuelle avatar Oct 11 '19 14:10 emmanuelle

Apologies, I realise now that I made a mistake in my example code

dcc.DatePickerRange(
    id='date-picker-range',
    start_date = dt(2017, 1, 31),
    end_date = dt(2018, 3, 21),
    min_date_allowed = dt(2017, 1, 31),
    max_date_allowed = dt(2018, 3, 21),
    initial_visible_month =dt(2017, 1, 31)
)

The problem is, when a user clicks each of the date boxes, the default month is set to January 2017, as expected from setting initial_visible_month. However, I would like the user be able to click the end date picker, and have another default month selected.

davenewham avatar Oct 14 '19 07:10 davenewham

Hi @davenewham did you find the solution? I'm facing the same issue. Thanks

rodrigo-inflightvr avatar May 15 '20 08:05 rodrigo-inflightvr

Nope, Sorry. I had a look into the component https://github.com/plotly/dash-core-components/blob/7dbf19a81570644ff516e853209fe6d92dd99e7a/src/fragments/DatePickerRange.react.js#L160 and I'm sure this is the problematic code.

davenewham avatar May 15 '20 10:05 davenewham

@davenewham

That function isn't works correctly. initial_visible_month is already converted by convertToMoment. convertToMoment handle falsy values like null and convert to not null value in following code. https://github.com/plotly/dash-core-components/blob/dev/src/utils/convertToMoment.js#L10-L21

Therefore, that function for initialVisibleMonth will receive non-null value even if specify None to initial_visible_month in python code.

Sheile avatar Jun 13 '20 16:06 Sheile

Facing the same issue. Stumbled upon this bug report :) We need something like final_visible_month or end_visible_month

https://www.loom.com/share/dc2c40e8a0f946ab91eda321d332ef38

karanrajagopalan avatar Jan 21 '22 10:01 karanrajagopalan