Hi,
I have a multipage dash app.
That i would like to load some data from the backend everytime when subpage is visited.
I create a dash app with dcc.Location and callbacks:
def init_app(config):
"""Initialize Dash App"""
app = DashProxy(
server=SERVER,
index_string=INDEX_STRING,
external_stylesheets=EXTERNAL_STYLESHEETS,
external_scripts=EXTERNAL_SCRIPTS,
use_pages=True,
update_title=None,
)
(...)
app.layout = dbc.Container(
[
dcc.Location(id="url", refresh=False),
(...)
dcc.Store(id="refresh_history_time", data=-1),
dash.page_container,
],
fluid=True,
)
_register_pages(...)
_create_callbacks(app, backend_url)
return app
Create callback using “url”, “pathname”
def create_callbacks(app, hostname):
"""Create callbacks"""
@app.callback(
Output("line_mapping", "data"),
Input("url", "pathname"),
prevent_initial_call=True,
)
def update_page(url):
logging.debug("Trigger line mapping")
if url != "/":
raise PreventUpdate
(...)
@app.callback(
Output("refresh_history_time", "data"),
Input("url", "pathname"),
prevent_initial_call=True,
)
def trigger_history_refresh(url):
if url != "/history":
raise PreventUpdate
logging.info("Trigger history")
return time.time()
and another callbacks for subpage tableupdate:
@app.callback(
Output("results_table", "rowData"),
Output("history_pagination", "active_page"),
Output("history_last_params", "data"),
Output("history_pagination", "max_value"),
Input("refresh_history_button", "n_clicks"),
Input("serial_search_button", "n_clicks"),
Input("refresh_history_time", "data"),
Input("history_pagination", "active_page"),
State(..)
prevent_initial_call=True,
)
def refresh_history( # pylint: disable=too-many-arguments,too-many-positional-arguments, too-many-locals, too-many-branches
_,
search_n_clicks, # pylint: disable=unused-argument
refresh_history_time, # pylint: disable=unused-argument
active_page,
(...)
):
"""Refresh history page"""
caller_id = get_caller_id(dash.callback_context)
logging.debug("History triggered by %s", caller_id)
params = {}
It works on localhost.
But in production, when dashboard is accessed from another machine, Is see url pathanme are both fired, but
refresh_history
is not.
I’ve tried removing trigger_history_refresh
callback completely and trigger refresh_history
directly from Input(“url”, “pathname”) but even on localhost it does not work.
I’d appreciate any ideas what could be wrong?
Thanks!