✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Structure project with database and SqlAlchemy

Hello,
I’m new to Dash and am looking to create some documentation in order to create a rather well-structured project.

I tried to follow the structure of this Dash project.
But there is one thing that differs and that blocks me. In okomarov’s project, he uses SQLAlchemy to register users but he’s not really using the data coming from this process. On my side, I get my data from a MySQL database using SQLAlchemy that I want to use in my graphs.
I am then lost about where I should register my database and how to retrieve data from it.
Here is the current structure of my project:

dashapp.py

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

config.py

class MysqlConfig(object):
  ...

app/init.py

def create_app():
    server = Flask(__name__)
    server.config.from_object(MysqlConfig)

    register_dashapp(server)

    return server

def register_dashapp(app):
    from app.page.layout import layout
    page = dash.Dash(server=app)
    with app.app_context():
        page.title = 'Title'
        page.layout = layout

app/models.py

class MyDBTable(db.Model):
  ...

app/data.py

from app.models import MyDBTable

data = MyDBTable.query_all()

app/page/layout.py

import dash_core_components as dcc
import dash_html_components as html

from app.data import data

layout = html.Div(children=[....

So I don’t know where to really put my call to the database.
I need to have created the app to save my db as: db = SQLAlchemy(app.server).
But I also need to have created db in order to create the app layout correctly.

I thought that it would be better in my register_dashapp method, but then I can’t retrieve the object db in the app/models

Any help would be really appreciated!