import dash_labs as dl
from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input

def page_name(i: int):
    return f"page{i}"

def make_page(i: int):
    page = DashBlueprint()
    page.layout = html.Div([html.H2(f"Page {i}"), html.Button('Click me!', id='btn'), html.Div(id='log')])

    @page.callback(Output('log', 'children'), Input('btn', 'n_clicks'))
    def on_click(n_clicks):
        return f"Hello world {n_clicks} from page {i}!"

    return page

app = DashProxy(prevent_initial_callbacks=True, plugins=[dl.plugins.pages])
# Register a few pages.
n_pages = 5
for i in range(n_pages):
    page = make_page(i)
    page.register(app, page_name(i), prefix=str(i))
# Setup main app layout.
app_shell = [html.H1("App shell"), dl.plugins.page_container]
navigation = html.Ul([html.Li(html.A(page_name(i), href=page_name(i))) for i in range(n_pages)])
app.layout = html.Div(app_shell + [navigation], style=dict(display="block"))

if __name__ == '__main__':
    app.run_server()
[((17, 6, 17, 75), 'dash_extensions.enrich.DashProxy', 'DashProxy', (), '', False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((8, 11, 8, 26), 'dash_extensions.enrich.DashBlueprint', 'DashBlueprint', ({}, {}), '()', False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((24, 13, 24, 33), 'dash_extensions.enrich.html.H1', 'html.H1', ({(24, 21, 24, 32): '"""App shell"""'}, {}), "('App shell')", False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((11, 19, 11, 44), 'dash_extensions.enrich.Output', 'Output', ({(11, 26, 11, 31): '"""log"""', (11, 33, 11, 43): '"""children"""'}, {}), "('log', 'children')", False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((11, 46, 11, 70), 'dash_extensions.enrich.Input', 'Input', ({(11, 52, 11, 57): '"""btn"""', (11, 59, 11, 69): '"""n_clicks"""'}, {}), "('btn', 'n_clicks')", False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((9, 28, 9, 48), 'dash_extensions.enrich.html.H2', 'html.H2', ({(9, 36, 9, 47): 'f"""Page {i}"""'}, {}), "(f'Page {i}')", False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((9, 50, 9, 84), 'dash_extensions.enrich.html.Button', 'html.Button', (), '', False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((9, 86, 9, 104), 'dash_extensions.enrich.html.Div', 'html.Div', (), '', False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n')]