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

Connecting my dash app to SQL or Mongo database

I’m planning to build a Plotly dashboard… what is the best scenario to connect a database (any type) to the application thus the charts can take the data from the database and draw the chart

Until a better answer comes along, I don’t believe it matters how you pull data out of a database. As long as it ends up in a Pandas dataframe. All the filtering and manipulation you see done in most Dash projects is done using dataframe functions. The database is disconnected as soon as possible (unless you’re doing real-time stuff). If you’re going to have multiple database feeds, SQLalchemy is probably your best bet because you can get some economies of data modeling there. Otherwise, I’d just pull straight into a Pandas dataframe with whatever library you use now.

2 Likes

@Mahmoud_Housam ,
I use SQLAlchemy. It was a long process for me to learn how to use it and connect it to Dash Flask. But it’s possible. Not sure if there are any other DBs that are simpler to work with??

1 Like

thanks a million max. Do you mean that I can use the pandas functions to read data from excel e.g and connect them to the charts drwan?

also, do you have any link for using SQL Alchemy that helps me?

thanks adam! any links for SQLAlchemy

It depends on the use of the database. If you’re looking for a live database which can update the charts live and always be connected online, then sqlalchemy. But my feeling is that you need something a lot simpler. @maxrottersman 's suggestion is good. Just use Pandas to read an Excel sheet into a dataframe, play around with the dataframe and build charts from it. Just Google “pd.read_csv pandas”.

1 Like

Hello!

Here is an article explaining how to query a MySQL database using the python package pymysql.

“Python & MySQL: baby-steps with pymysql” by Pyariksha Tiluk https://link.medium.com/IAXowsFXK3