Multi-Page App: how to use the content of the whole page_registry odict from a subpage?

Hmm, ok.

Here, check this out:

image

image

app.py:

import dash
from dash import Dash, Output, Input, dash_table, dcc, html, State

app = Dash(__name__, use_pages=True, pages_folder='pages_testing')

regPages = dash.page_registry

app.layout = html.Div([
    html.Div([dcc.Link(children=regPages[pg]['name'], href=regPages[pg]['path']) for pg in regPages if len(regPages[pg]['path'].split('/')) < 3],
             style={'height':'100%', 'display':'flex', 'flexDirection':'column', 'width':'150px'}),
    dash.page_container
], style={'display':'flex'})

app.run(port=12345, debug=True)

utils/generate_layout.py:

import dash
from dash import html, dcc

def getLayouts(url):
    regPages = dash.page_registry
    layout = []
    for pg in regPages:
        if url in regPages[pg]['path'] and len(regPages[pg]['path'].split('/'))>2:
            layout.append(regPages[pg]['layout'])
    return layout

def makeTempLayout(name):
    layout = html.Div(name)
    return layout

chapter1/all.py:

import dash
from utils.generate_layout import getLayouts

def layout():
    return getLayouts('/chapter1')

dash.register_page('chapter1', path='/chapter1', layout=layout)

chapterx/pagesy:

import dash
from utils.generate_layout import makeTempLayout

dash.register_page(__name__)

layout = makeTempLayout(__name__)

What are your thoughts on this?

1 Like