Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬Register for the Oct 27 webinar.

Basic CRUD in Dash DataTable and saving into DB - example in Python/Postgres or SQL

I am on the verge of giving up on Dash totally since I struggle so much to implement basic add row/delete row/update row(table) and to get database updated automatically. I don’t know why is it so difficult to this basic thing. My table is editable and on click or enter value in a cell it is updating DB automatically, also I need to delete row and update it. I am using Python/Postgres DB.

Is there any basic example on how to do this or does anyone here have a basic working example? The documentation Editable DataTable | Dash for Python Documentation | Plotly of adding new rows/columns etc isn’t complete, I don’t see how to figure out what value user inserted into cells. Any help is appreciated.

If anyone can help in any way, that would be great, it is very urgent.

You need to provide a minimum example of code that is not working for you but you expect it to be. There could be dozens of things that do not work in the way you expect them to work, provide any error you are getting or expected behavior vs. actual behavior. It’s impossible to guess what your problem is :).

Also it’s worth noting the DataTable is currently in Alpha, make sure you have the latest version installed as bugs are being constantly fixed.

There are two main problems:

  1. I have two events that happen when user arrives at the app. The first event is ‘Add New Row’ (button) click event which should insert new data into a database when user starts typing into a Datatable cells in a newly added row.

    The second event is update table which should update database if user starts typing anywhere except on a newly added row. I can’t distinguish between the two, between the newly added row that should do insert on typing and all other rows which should do update on user typing. I tried with n_clicks and everything I could think of but nothing works.

  2. I created a ‘delete selected rows’ link which should remove rows from the Datatable and from the database also. That doesn’t seem to be possible at all or I couldn’t find how to do it, no ideas for that at all.

It is almost 7pm here and if I go and change code now it would take me at least an hour because I am not allowed to share the original code and I have a deadline tomorrow. If you know what I could do in a few sentences or a link that I could look at, that would be great.

You can try to write some pseudo code or just some example app with a table, it is very hard to help you without seeing some code

If it’s helpful to anyone. here’s a simple crud app I created with Dash DataTable connected to PostgreSQL. (takes 8 seconds to load). And here’s the code.


This looks great! Thanks for sharing!