✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Dash URL like <param>/dash

Hi, I am looking for create a dash app with a URL like this example in flask, is it possible?

@app.route("/<tenant_name>/users")

I am using the first type file structure in the urls where each app is contained in a separate file. I would like to generate something like this, and pass this “tenant” param to dash app:

index_page = html.Div([

    html.Table([

        html.Thead(

            html.Tr([html.Th(('Dashboards'))]),

        className='thead-dark'),

        html.Tbody([

            html.Tr([html.Td(dcc.Link('Go to Page 1', href='<tenant>/apps/app1', className='alert-link'))]),

            html.Tr([html.Td(dcc.Link('Go to Page 2', href='<tenant>/apps/app2', className='alert-link'))])

        ])

    ], className='container table')

])

@app.callback(Output('page-content', 'children'),

              [Input('url', 'pathname')])

def display_page(pathname):

    if pathname == '<tenant>/apps/app1':

        return app1.layout
        #return app1.layout(<tenant>) ??? 

    elif pathname == '<tenant>/apps/app2':

        return app2.layout

    else:

        return index_page

Do I need to change to flask + dash? My app is totally dash. I am looking in the docs and did not find nothing like this yet.

Thanks for the help.

Does it have to be url paths? Would querystrings also be fine? So then you would do localhost:8050/?tenant=John and it would load the page for john.

from urllib.parse import urlparse, parse_qs

app.layout = html.Div([
                        dcc.Location(id='url', refresh=False),
                        html.Div(id='page-layout')
                    ])

@app.callback(
    Output('page-layout', 'children'),
    Input('url', 'href'))
def page_load(href):
    if not href:
        return html.Div()
    name = parse_qs(urlparse(href).query)["tenant"]
    return html.Div(f"Hello {name}")