I developed multi-page dash app with use_pages
set as True
in app.py
.
in pages/detail.py
file, the page is registered with path_template
so as to get the <product_id> from url.
dash.register_page(__name__, path_template="/details/<product_id>")
And inside the layout(product_id:str) function, i need to return the component generated using <product_id>, which also needs to define some callbacks to function.
details.py
dash.register_page(__name__, path_template="/details/<product_id>")
def layout(product_id:str = "", **kwargs):
layout = html.Div([
html.H3(children = 'Product_id: {}'.format(product_id)),
html.H5(children = 'Output', id=f"output-{product_id}"),
dcc.Input(value='Example', id=f"output-{product_id}")
])
@callback(
Output(f"output-{product_id}"', 'children'),
Input(f"output-{product_id}", 'value'),
)
def update_output(input_str:str):
return input_str
return layout
But the problem is that when i tried to define @callback inside the layout function, it did not function at all.
How can i define callbacks specific to components in layout function?