Hello colleagues!
I’ve been using dash for over a year, but recently decided to join you because the projects have become more complex
I have a dashboard with graphs, filters, tables. I get the data from the own function “msg_data()” - this is a pandas dataframe obtained using SQL. I need to update data with a certain period without restarting the project. Also I update the DatePickeRange component. I chose a solution using dcc.Interval(), but it doesn’t work correctly.
I’ll try to give an example of the main elements of my code:
DATA = msg_data()
app.layout = dbc.Container(
children=[
...
dcc.Graph(id='graph1'),
dcc.DatePickerRange(id='picker_range', ... ),
dcc.Interval(id='interval-component', interval=3*60*1000)
...
]
)
@app.callback(
Output('picker_range', 'max_date_allowed'),
Output('picker_range', 'end_date'),
Output('picker_range', 'start_date'),
Input('interval-component', 'n_intervals')
)
def update_data(n):
if n:
global DATA
DATA = msg_data()
day = datetime.date(datetime.now())
s_day = day - timedelta(days=29)
return day, day, s_day
@app.callback(
Output('graph1', 'figure'),
Input('picker_range', 'end_date'),
Input('picker_range', 'start_date')
)
def create_graph(e_day, s_day):
df = DATA
...
return figure
If I launch the project and open it in the browser, the data is updated every 3 minutes and everything is fine. But if I open the browser after the night, I see that the dates are correct in DatePickerRange, but there is no data for the new day in the graphs and tables. I wait 3 minutes and it appear.
I do not understand what the problem is.
Maybe the Interval component does not work without an observer (open browser)? How can I then trigger the component?
Perhaps the second callback (create_graph()) does not work offline?
The problem is that I have a project where I need to update data once every 24 hours and I don’t want to keep the browser open. I would also like to solve this without the windows task scheduler or Cron.
I also liked the idea of using flask-caching with filesystem storage, but to do this I also need to trigger the function somehow