Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo app for Dash to connect to PostgreSQL #259

Merged
merged 14 commits into from
Jul 29, 2024
2 changes: 1 addition & 1 deletion examples/dash/dash-connect-pgsql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PGPASSWORD='your_password'
Run `python -m pip install -r requirements.txt` to install all necessary packages.

## Upload dataset to your Postgres server
bryannho marked this conversation as resolved.
Show resolved Hide resolved
We will upload the data in `student-mat-min.csv` and `student-por-min.csv` in the `data` folder. Run `python upload.py` locally to upload the dataset to your PostgreSQL.
You can download the dataset I'm using [here](https://archive.ics.uci.edu/dataset/320/student+performance) and store them in the `data` folder. Next, `cd data` and run `python csv_mod.py` to obtain `student-mat-min.csv` and `student-por-min.csv`, the extracted dataset that we will be uploading. Run `python upload.py` locally to upload the dataset to your PostgreSQL.

## Local testing
Add the below lines to your `app.py`
Expand Down
17 changes: 17 additions & 0 deletions examples/dash/dash-connect-pgsql/data/csv_mod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pandas as pd

csv_mods = {
"student-mat.csv": "student-mat-min.csv",
"student-por.csv": "student-por-min.csv"
}

for csv_cur, csv_conv in csv_mods.items():
df = pd.read_csv(csv_cur, sep=";")
#print(df.columns)
df = df[["school", "sex", "romantic_status", "age",
"mother_occupation", "father_occupation",
"health", "study_time", "absences", "final_grade"]]
print(df.head())
df.to_csv(csv_conv)
bryannho marked this conversation as resolved.
Show resolved Hide resolved