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:
from app import create_app app = create_app() if __name__ == '__main__': app.run_server(debug=True)
class MysqlConfig(object): ...
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
class MyDBTable(db.Model): ...
from app.models import MyDBTable data = MyDBTable.query_all()
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
Any help would be really appreciated!