Using Value from Callback as Datepicker Input (Problem in Docker)

#1

Hello,
I have a problem with Dash Datepicker Input on my app. My app is in Docker on VPS, and it won’t update dynamic value such as “datetime.date.today()”. This is what I do before :slight_smile:

dcc.DatePickerRange(
min_date_allowed=datetime.date(2013, 1, 1),
max_date_allowed=datetime.date.today(),
# initial_visible_month=datetime.date.today(),
start_date=datetime.date.today()-datetime.timedelta(days=14),
end_date=datetime.date.today()
)

When I run the docker on 14th May, as an example, the end_date of datepicker is in true value (14th May). But, when I open the app tomorrow without restarting the docker, it still shows ‘14th May’ instead of 15th May.
Does anyone know how to solve this problem? Can I define values from app.callback and trigger the “datetime.date.today()” when load the page and use them as a value in “start_date” and “end_date”? Thanks.

#2

Uh oh, I solved the problem on my own.
Actually I need to define the start_date and end_date first in the dcc in the app.layout, so here is the example :

dcc.DatePickerRange(
id=‘pilihtgl’,
min_date_allowed=datetime.date(2013, 1, 1),
max_date_allowed=datetime.date.today(),
# initial_visible_month=datetime.date.today(),
start_date=None,
end_date=None
)

and here is the app callback :

@app.callback([Output(‘pilihtgl’,‘start_date’),
Output(‘pilihtgl’, ‘end_date’)],
[Input(‘url_squad’, ‘pathname’)])
def balik_ke_menu(input):
return datetime.date.today()-datetime.timedelta(days=14), datetime.date.today()

(I use ‘url_squad’ to trigger the query of datetime every page loaded)