Forums

Multipage Dash app not displaying sidebar or tabs

I have a multipage Dash app that works as intended locally. However, when I upload it the sidebar and tabs are missing. The main page shows only the first "page" but in the upper part of the screen where the tabs are displayed locally. I've replicated the behavior on Heroku (similar platform) so it must be something with how it is rendering (guess) or how the page layout is coded (second guess).

Here's what it looks like locally: https://freeimage.host/i/HUvhS29

Here is what is displayed on pythonanywhere (also Heroku): https://freeimage.host/i/HUvjzQ4

I've organized the app into an app.py file

app = Dash(
    __name__,
    use_pages=True,
    external_stylesheets=[
        dbc.themes.FLATLY,
        "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
    ],
    meta_tags=[
        {"name": "viewport", "content": "width=device-width, initial-scale=1"}
    ],
    suppress_callback_exceptions=True
)

And then an index.py file that handles the page layout:

sidebar_header = dbc.Row(
    [
        html.A(
        dbc.Col(
            [
                #dbc.Col(html.Img(src = "assets/ATS_green.jpg", height= "75px")),
            ]
        )
    ),
    ]
)

sidebar = html.Div(
    [
        sidebar_header,
        html.Div(
            [
                html.Hr(),
                html.P("Select Stock: \n", style={"font-weight":"bold"}, className="lead"),
                html.P("Pick your favorite!"),
            ],
            id="blurb",
        ),
        dbc.Collapse([
            create_dropdown('tickers-dropdown','Ticker Symbol',['AAPL', 'AMZN', 'NVDA', 'MSFT'], 'AAPL'),
            html.Div(
                [
                    html.H5("Analyst Rating:",style={"font-weight":"bold"}),
                    dbc.Table(html.Tbody(id='analyst-rating'),  
                        bordered=True,
                        dark=False,
                        hover=False,
                        responsive=True,
                        striped=False,
                        color="warning",
                        style={"font-weight":"bold",
                                "color":"black"},
                    )
                ],className="mt-5 mb-3"
            ),
            html.P(["1 - Strong Buy",html.Br(),\
                    "2 - Buy",html.Br(),\
                    "3 - Hold",html.Br(),\
                    "4 - Underperform",html.Br(),\
                    "5 - Sell",html.Br()
                   ]),
        ],id="collapse",
        ),
    ],
    id="sidebar",
)



app.layout = dbc.Container(
    [
        # dcc.Location(id='url', refresh=True, pathname='/tab0'),
        sidebar,
        html.Div(
            [
                html.H1("Stock Explorer", className="mb-3",style={"border-left":"5px solid #f89406","padding-left":"5px"}),
                dbc.Nav(
                    [
                        dbc.NavItem(
                            dbc.NavLink(
                                [
                                    # html.I(className=icon),
                                    html.Span(page['name']),
                                ], active="exact", href=page['relative_path']
                            ), className='sidebar-items'
                        )
                        for page in dash.page_registry.values()
                    ],
                    pills=True,
                    justified=True,
                    className="shadow mb-5 rounded border-light"
                ),
                dash.page_container,
            ],id='page-content'
        ),
    ],fluid=True
)

(there is a third file with the callbacks defined etc but Im leaving that off for now to conserve space).

Anyone have similar issues with Dash multipage apps where the sidebar and tabs are missing? More importantly, anyone have the issue then solve it?

Thanks in advance, Dwayne

What do you see when you compare what is visible in your web browser dev tool when you run it locally and on PythonAnywhere?

When I look at the dev output, I can see the PythonAnywhere app is missing the entire 'sidebar' section of the html object. This section is clearly present locally.

PA dev inspection: https://ibb.co/fGJRFrv

Local dev inspection: https://ibb.co/TgQxbnK

Somehow the html rendered on PythonAnywhere doesn't include the same page layout that shows locally.

What do you see in the network tab of the dev tools?

I see a few differences:

PA Network tab: https://ibb.co/jHZbFKy

Local Network tab: https://ibb.co/pWk7bVg

Seems like a few components aren't loading. Like the dropdown list, dash_echarts, etc.

Did you check your app's error log on PA for any meaningful / correlated errors?

I did. In fact I deleted the app and started over. Same code base. We configured wsgi file, virtualenvs dir, etc. Then I cleared the logs to get rid of any old msgs. Reloaded the web app and checked the logs.

Error log was still empty. No errors on the new app.

Access log showed where it was fetching the remote CSS page, then some (but not all) local packages the app imports.

Server log had no errors. Showed where it set the Pythonhome env var to the correct virtualsnvs directory.

So Im still stumped. Im wondering if Pythonanywhere doesn't work with dash_echarts perhaps? But if that was the case, I'd suspect just the graph wouldnt display, but I'd still see the sidebar and tab elements. Those are clearly missing from the deploy (but definately present in the code and works as epected locally)

Thanks.

Could you possibly add some logging to narrow down exactly what is failing?