0

I try to learn Dash, using some internet examples. My folderstructure is:

Python
 - chapter_02
  - app_v2_1.py

And my code is:

import dash
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
from dash.dependencies import Output, Input
import pandas as pd


app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

poverty_data = pd.read_csv('data/PovStatsData.csv')

app.layout = html.Div([
html.H1('Poverty And Equity Database'),
html.H2('The World Bank'),
dcc.Dropdown(id='country',
             options=[{'label': country, 'value': country}
                      for country in poverty_data['Country Name'].unique()]),
html.Br(),
html.Div(id='report'),
html.Br(),
dbc.Tabs([
   dbc.Tab([
       html.Ul([
           html.Br(),
           html.Li('Number of Economies: 170'),
           html.Li('Temporal Coverage: 1974 - 2019'),
           html.Li('Update Frequency: Quarterly'),
           html.Li('Last Updated: March 18, 2020'),
           html.Li([
               'Source: ',
               html.A('https://datacatalog.worldbank.org/dataset/poverty-and-equity-database',
                      href='https://datacatalog.worldbank.org/dataset/poverty-and-equity-database')
           ])
       ])

   ], label='Key Facts'),
    dbc.Tab([
        html.Ul([
            html.Br(),
            html.Li('Book title: Interactive Dashboards and Data Apps with Plotly and Dash'),
            html.Li(['GitHub repo: ',
                     html.A('https://github.com/PacktPublishing/Interactive-Dashboards-and-Data-Apps-with-Plotly-and-Dash',
                            href='https://github.com/PacktPublishing/Interactive-Dashboards-and-Data-Apps-with-Plotly-and-Dash')
                     ])
        ])
    ], label='Project Info')
]),

])


@app.callback(Output('report', 'children'),
          Input('country', 'value'))
def display_country_report(country):
if country is None:
    return ''

filtered_df = poverty_data[(poverty_data['Country Name']==country) &
                           (poverty_data['Indicator Name']=='Population, total')]
population = filtered_df.loc[:, '2010'].values[0]

return [html.H3(country),
        f'The population of {country} in 2010 was {population:,.0f}.']


if __name__ == '__main__':
app.run_server(debug=True)

I get the error "No module named app_v2_1"

I know it has something to do with my structure and need to set, maybe, application_root or something. But how to do that in Dash? I searched for "application_root dash" but could not find the answer. probably looking in the wrong direction.

hacking_mike
  • 1,005
  • 1
  • 8
  • 22
  • This probably has nothing to do with Dash, see [Python error "ImportError: No module named"](https://stackoverflow.com/questions/338768/python-error-importerror-no-module-named). – EricLavault Sep 29 '22 at 10:57

0 Answers0