I am using dash for my dashboard and is deployed on AWS Elastic Beanstalk.
There is an issue in Datepicker.I am using max_date_allowed=dt.date(dt.now())
So the day the app is deployed everything worked fine. But from the next day, the max_date_allowed is stuck to the date, the app is deployed and we can't choose date beyond the date the app is deployed.
It works again only if we choose in the environment, restart app server(s) from the action menu.
What could be the issue here?
Below is the date picker snippet we used.
dcc.Tabs([
dcc.Tab(label='DDR by Date (Default DDR - Last Day)', value='tab-1', children=[
dcc.DatePickerSingle(
id='my-date-picker-single',
min_date_allowed=dt(2020, 1, 18),
max_date_allowed=dt.date(dt.now()),
initial_visible_month=dt.date(dt.now()),
placeholder='Select a date',
display_format='DD/MM/YYYY'
),
html.Button(id='submit-button', n_clicks=0, children='Submit'),
html.Div(id='output-container-date-picker-single')
]),
Assuming that the code snippet is part of the app layout definition, the behavior you see is intended. This code is executed when the app starts, and dt.date(dt.now()) is thus evaluated at this time only.
There are (at least) two common ways to achieve what you want,
Wrap your layout definition in a function and assign the function instance as the app layout. The code would be something like app.layout = make_my_layout_function. By assigning a function, the app layout code will be evaluated each time a user visits you page. See more details in the documentation (scroll to "Updates on Page Load").
Assign the non-static default value, in your case max_date_allowed, via a callback. Since callbacks are executed on page load (unless you actively prevent it), the value will be updated as intended.
My approach to this would be to use an interval
Set the interval to fire say every hour and then use a callback to update the max_date_allowed
Taking this approach will eliminate the requirement for the user to reload the page to update
e.g.
@app.callback(Output("date-picker", "max_date_allowed"),
[Input("interval_hours", "n_interval")])
def update_max_date_allowed(n):
return dt.date(dt.now())