Black Lives Matter. Please consider donating to Black Girls Code today.

DatePickerRange initial values

Hi

I have a DatePickerRange control on a Dash page. I want to set the initial start_date to be 2 weeks ago and the end_date to be today every time the page loads (the user can then of course modify those dates).

Is there any way to do this without utilising callbacks to set the initial values?

e.g. something like:
dcc.DatePickerRange(
id=“date-range-picker”,
end_date=get_end_date(),
start_date=get_start_date(),
)

?

Currently the above example will not recompute the values of these functions when the page loads - so tomorrow, the initial values will be a day out of date!

The question is for all initial values of dash controls.

Thanks,
Julian

If app.layout is a function, then it will be called on every page load. Inside that function you can do a datetime.datetime.now(). See “Updates on page load” here: https://dash.plot.ly/live-updates

1 Like