Dash Labs - page_registry doesn’t have all of the pages registered yet?


when layout() is run in my file the page_registry doesn’t have all of the pages registered yet?

I spend hours trying to fix this But I didn’t know Where is the problem ? why I cant see all of my pages !

Hi @sanae

If you try to access the dash.page_registry from within the pages folder, then it’s likely that the page_registry dict is not complete. The dict is created when dash.register_page() is called when loading each page from the pages folder.

To get around this issue, you can create the offcanvas menu from the app.py file or by creating in it a function. You can see an example of this in the dash-labs docs: /docs/demos/multi_page_layout_functions

1 Like

Is there any problem with my app.py ?

app = dash.Dash(
    __name__,
    plugins=[dl.plugins.pages],
    external_stylesheets=[dbc.themes.BOOTSTRAP]
)
import json
registry = {a:{c:d for c, d in b.items() if c != 'layout'} for a, b in dash.page_registry.items()}
print(json.dumps(registry, indent=4))

#offcanvas  =
app.layout = dbc.Container([
    html.Div(
    [
       dbc.Button(
           "Open scrollable offcanvas",
           id="open-offcanvas-scrollable",
        n_clicks=0,
        ),
        dbc.Offcanvas(
            dbc.ListGroup(
               [
                   dbc.ListGroupItem(page["name"], href=page["path"])
                   for page in dash.page_registry.values()
                   if page["module"] != "pages.not_found_404"
                   # if not page["path"].startswith("/404")
             ]
            ),
        id="offcanvas-scrollable",
        scrollable=True,
        title="Scrollable Offcanvas",
        is_open=False,
        ),
        ]
)
    , dl.plugins.page_container],
   fluid=True,
)
#__
@app.callback(
    Output("offcanvas-scrollable", "is_open"),
    Input("open-offcanvas-scrollable", "n_clicks"),
    State("offcanvas-scrollable", "is_open"),
)
def toggle_offcanvas_scrollable(n1, is_open):
    if n1:
        return not is_open
    return is_open
if __name__ == "__main__":
    app.run_server(debug=True)

Hi @sanae
The app.py and the offcanvas looks fine to me. What do you see when you print the registry? How are the missing pages registered with `dash.register_page()’ ?

1 Like

In missing pages

I put in home
dash.register_page(
name, name=“Home”, path="/"
)
in others
dash.register_page(
name, name=“example”
)

Thank you @AnnMarieW I’ll try another idea like multipages with a sidebar