Black Lives Matter. Please consider donating to Black Girls Code today.

Connect to mysql to store inputs from the dash app

I’ve built a dash app which takes inputs and does some calculations and prints some text. I now want to connect dash to SQL(I am currently using MySQL workbench on my windows 10 laptop) to store inputs from dash app after submit button. Has anyone done this or how do i go about doing it?

Hi Naveen,

Yes, this is possible.

You gonna need a few things. I personally work with SqlAlchemy, Pandas and a few callbacks.

I don’t have a simple script for you, but I can explain the steps.

  • First make sure you have a connection with the database by using SqlAlchemy.
  • Your already do some calculations and print some text. So your already have a function. Expand this function to store these calculations and text in for instance a Pandas dataframe.
  • Next, create a callback that is triggered by pressing the button. This buttons sends the data to the database. You can do this with the ‘df.to_sql()’ function of Pandas.

So I advice you to learn about Pandas (to_sql) and SqlAlchemy (or perhaps you already know this).

P.S. Setting up the connection with the database was a hassle for me the first time.

Good luck

If you need anymore help, let me know.

Greetings Sempah

1 Like

will sure try it. I’m sure i’m gonna have more doubts.