Using Variable Paths

Hello! I am working on recreating the example on variable paths here: https://dash.plotly.com/urls (the single variable example)

Here is what I have so far:

import dash
from dash import html

app = DashProxy(transforms=[MultiplexerTransform()],
                external_stylesheets=[dbc.themes.BOOTSTRAP, dbc.icons.FONT_AWESOME])


dash_labs.plugins.register_page(__name__, path_template="/testing/<report_id>")


def serve_layout(report_id=None):
    return html.Div(
        f"The user requested report ID: {report_id}."
    )

app.layout = serve_layout

if __name__ == '__main__':
    app.run_server(debug=False, port=8058)

When I type in “/testing/7”, my app is still returning “None” for the statement using {report_id}.

Hi @kelly_gfc

I recommend trying pages in dash>=2.5.1

You can find lots of examples with path variables here:
GitHub - AnnMarieW/dash-multi-page-app-demos: Minimal examples of multi-page apps using the pages feature in dash>=2.5.1

I recommend trying this app first: multi_page_basics.

This example also has path variables - it shows passing variables from a link in a table to a page with more details on the selected item.

I see you are also using dash-extensions. This example uses MultiplexerTransform to sync components between pages.

hi @AnnMarieW

I’m using Dash 2.6.0.

Is a multi page app necessary to be able to use the variable path feature? I’m only interested in that feature and I don’t need a multi page app for this project.

Yes, that feature is only available when use_pages=True when you instantiate the app.

However, if you are not building a multi-page app, you could just use dcc.Location and splice the pathname to get the report_id

Sweet. I’ll look into that. Thank you!