Hello,
I am creating a multipage Dash app. For this, I have created a Sidebar which allows me to switch between pages with selecting the page in a dropdown menu where each option is a dcc.Link object (see code below). After changing to a specific page, the URL in the browser changes from localhost:8050
to, e.g. localhost:8050/adp
and all the HTML blocks defined in the layout of this pages are displayed.
I have registered every page with the parameter
dash.register_page(
__name__,
path = '...'
In my main app.layout I have the component dash.page_container
to display the selected page.
On the new page, I have many callbacks. These callbacks I have created in the following manner:
@callback(
Output('workspaceDropdown', 'options'),
Input('url', 'pathname'),
prevent_initial_call=True
)
Before stating the function with this callback, I already have created the dcc.Dropdown
object with the ID workspaceDropdown
Right at the beginning I have a simple print statement which tells me whether or not the function was executed. This statement never shows up in the terminal from which I assume that the function is not executed.
Do I need to add something to the layout of this page or to all the callbacks that they are recognized and executed properly?
sidebar = html.Div(
[
html.P('Select the page you want to load', className='lead'), #explanation of dropdown menue
html.Div([
dcc.Dropdown(
options = [
{'label': dcc.Link(children='Hello World' , href='/' , style = LINK_STYLE), 'value': '/'},
{'label': dcc.Link(children='ADP' , href='/adp' , style = LINK_STYLE), 'value': '/adp'}
],
id='pageSelected'),
]),
],
style=SIDEBAR_STYLE, #use defined style of sidebar
)
@callback(
Output('workspaceDropdown', 'options'),
Input('url', 'pathname'),
prevent_initial_call=True
)
def getWorkspaces(path):
print('path in getWorkspaces: ' + str(path))
try:
if path == '/adp':
print('get_workspaces')
workspaces = get_workspaces()
workspacesList = list(workspaces.keys())
return workspacesList
except IndexError as e:
None
return []
This function is just one example. All the callbacks on the other pages are not executed as well.
I hope someone can help me,
All the best,
Clonky