I am using a DatePickerSingle component that by default sets the current day as the value so that once the user opens the web application, will be able to select a date while the today date is already set. The problem is that once I deploy the application the pre-set default day is always the deployment date and not the actual today date.
It seems that somehow the date is cached serverside and I cannot find a way to prevent this from happening.
Can you provide sample of code? I have done something similar - I set the intial
date and not the
value - code snippet below: You could change
placeholder to be a datestring via datetime’s strftime() function.
datetime.strftime(datetime.today(), '%Y-%m-%d'), '%Y-%m-%d'),
where get_pacific_time is:
utc_now = pytz.utc.localize(datetime.utcnow())
pst_now = utc_now.astimezone(pytz.timezone("America/Los_Angeles"))
Well, the code that provides this behaviour is the following:
day_d = datetime.now()+timedelta(days=1)
day_d = datetime.strftime(day_d, '%Y-%m-%d')
dcc.DatePickerSingle(id='system-date', date = str(day_d), display_format='YYYY-MM-DD')
This code block is included in a function which is called later like this:
app.layout = html.Div(children = [header()], className="container")
The datepicker is fully fucntional but the pre-set day is always the same as the day of the deployment of the application. It’s not cached locally because I’ve tried from several browsers.
If the app is loaded and the page never refreshed, then I can see how the date picker value is not updated. You can use dcc.Interval to set a refresh interval on the component. Also, what about the callback for the date picker that gets fired on page load? Do you have anything that would prevent its update (i.e. for many of my callbacks, I have checks in place that prevent the callback from executing if the user didn’t invoke the action).