I am trying to create a multi-page app using Dash. I have a table on my first page that contains rows of data. When a user selects a row and clicks a button, I want to load in a new page w/ the ID of the row that was selected.
I can navigate to that directly using the URL, but I can't get it to work programmatically. Is my idea way off? Here is some code. The error I get is that the return of the callback function is expecting a different type than dcc.location
layout = dbc.Container([
html.Div(children='Experiement Results'),
html.Div(id="hidden_div_for_redirect_callback"),
dbc.Button("Image Browser", id='image-browser', color="dark", className="me-1"),
dbc.Button("Experiment Result", id='exp-result', color="dark", className="me-1"),
html.Div([
dash_table.DataTable(data=df,
columns=[{'id':c, 'name':get_field_display_name(c), 'type':get_field_type(c)} for c in df[0].keys()],
page_size=100,
row_selectable='single',
cell_selectable=True,
filter_action='native',
)
])
])
@callback(
(
Output("hidden_div_for_redirect_callback", "children"),
Input('image-browser', 'n_clicks'),
Input('exp-result', 'n_clicks'),
Input('tbl', 'selected_rows'),
),
prevent_initial_call=True)
def button_pressed(image_browser, exp_result, active_cell):
changed_id = [p['prop_id'] for p in callback_context.triggered][0]
if 'image-browser' in changed_id:
return dcc.Location(pathname='/imagebrowser/{ac}'.format(ac=active_cell[0]), id="12412", refresh=True)
elif 'exp-result' in changed_id:
return dcc.Location(pathname='/expresult/{ac}'.format(ac=active_cell[0]), id="146", refresh=True)
else:
return None
The pages are registered pages: i.e:
register_page(__name__, path_template="/expresult/<result_id>")