I have a multi page Dash app.
app.py:
app = dash.Dash(__name__, use_pages=True, suppress_callback_exceptions=True)
...
I then have a page:
pages/resources.py:
dash.register_page(__name__, order=4, title='️ Resources')
Layout is defined as (note table which is a variable containing a HTML table):
def layout(**other_unknown_query_strings):
return dbc.Container([... + table...])
I put an observer on a file (watchdog):
event_handler = FileChangeHandler()
observer = Observer()
observer.schedule(event_handler, path='resources_reserve.yaml', recursive=False)
observer.start()
Now in FileChangeHandler I change table and then want to trigger a refresh of the layout.
Is there any elegant way of achieving this?
Not sure if it's elegant but one idea would be to :
Keep track of the table last modification timestamp (global variable updated in
FileChangeHandler).In the layout, add :
dcc.Storeto keep track of the last time the layout refreshed.dcc.Intervalcomponent.layout()when refreshing, a container whosechildrenis the output of that function.Add a callback with the interval component as input, the store data as state, and the layout container children as output: compare the (global) table-changed timestamp and the (client) layout-refreshed timestamp and refresh if necessary, otherwise
raise PreventUpdate.