I am about to scratch a dash application as interface to a database.
Dash reads the initial state of a table in a database and displays the content in a table.
One variable/column of the table is a simple dropdown that the user can use to edit the data.
Once the edit is performed, dash writes the value to the database.
I am ok with the technical implementation of this simple example, however I will likely be facing the concurrent users issue.
User A opens the app, reads data, displays them in the datatable
User B opens the app, reads data, displays them in the datatable
User A changes row id 1 dropdown column to value “1”, dash writes “1” in dropdown column where row id=1
User B changes row id 1 dropdown column to value “2”, dash writes “2” in dropdown column where row id=1
User A at this point displayed with “1” in dropdown column where row id=1, while that value is actually “2”.
The reality is a bit more complicated than the example as multiple values are conditional to other values, and dependencies could break quite easily in these types of situations.
Have any of you ever implemented something to prevent this in dash?
I could potentially compare the database data with the table data before the edit to see if they are still in sync, or I could deploy a check-in check-out functionalities, or maybe use some database features, maybe I could just compare timestamps.
I am here to read some inspirations, how you tackled this situation when you faced it.
Comparing timestamps is a good idea. You can refresh several times with dcc.Interval. I don’t think you meant that it needed something as complex as team collaboration in real time.
thanks @stu , yes definitely I just need an easy implementation.
I am just trying to replace excel spreadsheet with dash tables, so just implementing the usual behaviour of shared excel spreadsheet where at any update, clicking save, if the edits made by two different users are overlapping an error is thrown, while if other cells were updated by other users then the edit goes in and the cells changed by others are updated.
I think I’ll just impute a timestamp variable at every row, updating it with the timestamp of the latest edit when any of the cell of that specific row is updated. once the edit is triggered, I’ll make dash fetch the timestamp of the row, compare it with the one present in the original data (already in the table), if they match then the update is posted to the database, while the complete dataset fetched from the database and fed to the datatable.
I’ll scratch some code during the weekend, let’s see what I come up with.
Thanks for your suggestion!