dash-core-components
dash-core-components copied to clipboard
Unable to specify defaults for individual date pickers in DatePickerRange
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
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)
)
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
?
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.
Hi @davenewham did you find the solution? I'm facing the same issue. Thanks
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
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.
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