My Dash plotly app not working

Hi, I have scripted an web app with dash.plotly. But having issues with it. Can anyone help me with it? I need it to be submitted tonight as a project.

Hello @moizbaloch1,

Welcome to the community!

This request is very vague, could you please provide more info about where you are having the issue.

Also, can you provide a MRE:

import dash
from dash import html, dcc

PopulationDistribution = dash.Dash(__name__, use_pages=True)

PopulationDistribution.layout = html.Div(
    [
        # main app framework
        html.Div("WorldWide Population Distribution", style={'fontSize':50, 'textAlign':'center'}),
        html.Div([
            dcc.Link(page['name']+"  |  ", href=page['path'])
            for page in dash.page_registry.values()
        ]),
        html.Hr(),

        # content of each page
        dash.page_container
    ]
)


if __name__ == "__main__":
    PopulationDistribution.run(debug=True)`Preformatted text`

Thank you, @moizbaloch1.

Do you have a pages folder in that directory? If not, your app wont load because it cant parse through any files.

Also, here is a standard way to initialize:

import dash
from dash import html, dcc, Dash

app = Dash(__name__, use_pages=True)

app.layout = html.Div(
    [
        # main app framework
        html.Div("WorldWide Population Distribution", style={'fontSize':50, 'textAlign':'center'}),
        html.Div([
            dcc.Link(page['name']+"  |  ", href=page['path'])
            for page in dash.page_registry.values()
        ]),
        html.Hr(),

        # content of each page
        dash.page_container
    ]
)


if __name__ == "__main__":
    app.run(debug=True, port=12345)

The main thing was that typically we call it app, that way its easier to reference and copy & paste code. :slight_smile:

I have directory for pages and also data file

Hmm…

The application runs fine if I have a pages_folder.

Are you having issues with a specific folder? Can you copy my code and use it? Does it work?

1 Like

Appis loading but , when i move to another page. there is an error that page not found Error 404

Can you post your other pages.py?

Do you have layout = in each?

import dash
from dash import dcc, html
import plotly.express as px
import pandas as pd 

dash.register_page(__name__)

df = pd.read_csv(r'd:\New\Data.csv')

layout = html.Div(
    [
        dcc.Dropdown([x for x in df.year.unique()], id='cont-choice', style={'width':'50%'}),
        dcc.Graph(id='line-fig',
                  figure=px.bar(df, x='country', y='population'))
    ]
)

Another Page> Blockquote

import dash
from dash import dcc, html
import plotly.express as px
import pandas as pd

dash.register_page(name)

df = pd.read_csv(r’d:\New\Data.csv’)

layout = html.Div(
[
dcc.Dropdown([x for x in df.year.unique()], id=‘cont-choice’, style={‘width’:‘50%’}),
dcc.Graph(id=‘line-fig’,
figure=px.bar(df, x=‘country’, y=‘population’))
]
)

Are there any errors in the console or anything that could shed some light?

if its okay, Can I email it to you , the zip file.

Issue is naming of the files leads to an incompatible path.

However, you can declare the path when you register the page and then it will work. :slight_smile:

from dash import dcc, html
import plotly.express as px
import pandas as pd

dash.register_page(__name__, path='/pop_per_country_selected')

df = pd.read_csv(r'Data.csv')

layout = html.Div(
    [
        dcc.Dropdown([x for x in df.year.unique()], id='cont-choice', style={'width':'50%'}),
        dcc.Graph(id='line-fig',
                  figure=px.bar(df, x='country', y='population'))
    ]
)

1 Like

Thank you, still not working for me though

You’ll need to do it on all your files.

Is your main page loading with the graphs?

1 Like