How to structure Dash web app

Hi everyone,

I need structure my dash app. I want to add database my dash app. But I get circular error so I cannot use my db variable from my dash app. It is obviously it related with app structure.

Please help me to set structure of my app correctly. Give me article or tutorial for this topics

hi @Sanan009
Here’s a post about structuring the directory of a Dash app in case it’s helpful.

Can you provide more information on the db variable and how it clashes with the Dash app.


Thank you Mr. Adam for helping

In my case

I want to connect the database (PostgreSQL) to my dash app. But I get circular error when db = SQLAlchemy() I import db variable to other page (script).

Please it is important for me. So that reason I cannot complete my project.

If you provide tutorial for structure and deploying web application in local server I will be appreciate.

In the past I did something as below:

import psycopg2 as pg2

             [Input('update', 'n_intervals')])
def update_data(interval):
    global df
    conn = pg2.connect(database='********',user='*******',password='*******')
    cur = conn.cursor()
    cur.execute('''SELECT * FROM public."********"''')
    data = cur.fetchall()
    cols = []
    for elt in cur.description:
    df = pd.DataFrame(data=data, columns=cols)
    df['Date'] = pd.to_datetime(df['Date'])
    df = df.sort_values(['Date'], ascending=[True])
    df['Date_2'] = df['Date']
    df.set_index('Date_2', inplace=True)
    df['invoiceTotal'] = df['invoiceTotal'].astype(float)
    return df.to_dict(orient='records')

As you see, I will load data from postgres and then return it to dcc.Store then use Store to create Graphs . Hope this help.

1 Like

This is my project and error.

Can you help for this situation

Sorry but I cannot see your capture.

1 Like

I have just updated my post. Please look at this

Could the problem be related to the circular import issues that Corey Schafer talked about in this video?

hi @Sanan009
it is best to add the code in pre-formatted text, not images, because images are hard to read, and are not reproducible.