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()
[((489, 558), 'dash_extensions.enrich.DashProxy', 'DashProxy', ([], {'prevent_initial_callbacks': '(True)', 'plugins': '[dl.plugins.pages]'}), '(prevent_initial_callbacks=True, plugins=[dl.plugins.pages])\n', (498, 558), False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((185, 200), 'dash_extensions.enrich.DashBlueprint', 'DashBlueprint', ([], {}), '()\n', (198, 200), False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((734, 754), 'dash_extensions.enrich.html.H1', 'html.H1', (['"""App shell"""'], {}), "('App shell')\n", (741, 754), False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((328, 353), 'dash_extensions.enrich.Output', 'Output', (['"""log"""', '"""children"""'], {}), "('log', 'children')\n", (334, 353), False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((355, 379), 'dash_extensions.enrich.Input', 'Input', (['"""btn"""', '"""n_clicks"""'], {}), "('btn', 'n_clicks')\n", (360, 379), False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((229, 249), 'dash_extensions.enrich.html.H2', 'html.H2', (['f"""Page {i}"""'], {}), "(f'Page {i}')\n", (236, 249), False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((251, 285), 'dash_extensions.enrich.html.Button', 'html.Button', (['"""Click me!"""'], {'id': '"""btn"""'}), "('Click me!', id='btn')\n", (262, 285), False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n'), ((287, 305), 'dash_extensions.enrich.html.Div', 'html.Div', ([], {'id': '"""log"""'}), "(id='log')\n", (295, 305), False, 'from dash_extensions.enrich import DashBlueprint, DashProxy, html, Output, Input\n')]