Multipage Dash app with Vanity URL

I have a multipage Dash App. The problem I am facing with Posit. Do you have any idea how to specify url for Dash app in idar connect, considering it is multipage app? If I specify custom URL only my homepage stays accessible and rest of the pages are not. My pages are pages folder and unable to redirect the user from home page to another page. I have DASH 2.8.
Any help or sample code is appreciated.

Here's a step-by-step guide..

  1. Install posit library.
  2. Import necessary libraries In your Dash app script.
import dash
from dash import dcc, html
from dash.dependencies import Input, Output
from posit import positRoute

  1. Create your Dash app as usual.
app = dash.Dash(__name__)

# Layout for the home page
app.layout = html.Div([
    html.H1("Welcome to the Home Page"),
    dcc.Link("Go to Page 1", href="/page-1"),
    dcc.Link("Go to Page 2", href="/page-2"),

# Callbacks to handle page navigation
    Output("page-content", "children"),
    [Input("url", "pathname")]
def display_page(pathname):
    if pathname == "/page-1":
        return html.H1("This is Page 1")
    elif pathname == "/page-2":
        return html.H1("This is Page 2")
        return html.H1("Welcome to the Home Page")

# Run the app
if __name__ == "__main__":

  1. Define custom URLs using positRoute Use the positRoute decorator to define custom URLs for your pages.
def render_page_1():
    return display_page("/page-1")

def render_page_2():
    return display_page("/page-2")

  1. Run the app with Posit To run your Dash app with Posit, replace the app.run_server() line with the following code.
if __name__ == "__main__":
    from posit import posit_server
    posit_server(app, "/")

Now your Dash app should have custom URLs defined for each page, and the navigation between pages should work correctly that can verify on any online tool such as to get its redirection chain and status code.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.