How to attach a callback to specific column of multiple data-tables?

Hi all,

I currently have a system set up where I have multiple data tables in separate tabs, which have editable fields. At the moment, I have a custom field in the ID dictionary of these tables, which allows me to identify them using a MATCH callback, which pulls down the data and returns a modified version of the same table.

This functionality works completely as intended, however, I want the callback to only fire when a specific column of the datatable is edited, rather than anywhere on the entire table. I still want the callback to pull the entire datatable data down, and to output a modified version of the same datatable data, however, it should only fire for one, specific column. I also need this to work across the several datatables in the tab setup.

I can’t figure out how to modify the callback to target a specific column, which still matching with the particular datatable using the MATCH construct. Any help anyone could offer with this would be great, thanks.

Hi @plantedsneeze and welcome to the Dash Community.

You can use active_cell as input and then ask about the column name:

In this link you can find examples about that:

1 Like

Hi @Eduardo thanks so much for your suggestion. I just tried it out and while it looks like it would work, unfortunately it didn’t quite do the job.

There are two issues with it unfortunately. The first one is more a ‘cosmetic’ or ‘user experience’ type of issue; the page will do a quick reload (with nothing changed) every time a cell in the table is clicked. This is an editable table as well, so it is unfortunately very annoying for the user to have that flash and refresh every time (even though PreventUpdate does stop the content from changing).

The other, more serious issue is that the column in question which I actually want to use as the callback input, is a dropdown column. When I change the value in there, it doesn’t actually make the cell active… so the callback doesn’t fire on a change with that column. Unfortunately… that means that it won’t work in this case :confused:

Any other ideas about how I can attach the callback to that specific column (and it is across a number of tabbed tables), while still pulling the MATCHed table into the function as a State?

Thanks again for taking the time to help, I really appreciate it.

Hey @plantedsneeze

To avoid the first problem you can use the active_cell as State instead of as Input and use another event to trigger the callback to check the active_cell info about the column.

But if the column is a dropdown and do not work using active_cell I think you need to use the value of the dropdown in your callback, I never used dropdowns insde a callback, because of that I can’t say how to implement it, but I sure that my friend @AnnMarieW will give you the best solution as allways do.

1 Like

Hmm I don’t know if I can give the “best solution” but thanks for your kind words @Eduardo.

There is no way I know of to trigger a callback by column. If the purpose is to reduce the amount of data transferred on the network, you could check if any data in that column is changed before updating the Output.

1 Like

Thanks for the help both of you. The data transferred by the network isn’t a concern, however, I don’t want the page to do a mini refresh every time a cell is clicked (which active_cell seems to do, though as above, there could possibly be some workaround for), and I don’t want the other cells in the table to cause any callback to be fired. I only want one column of the table to fire a callback when changed. That column is formatted as a dropdown in the datatable, so active_cell doesn’t even work on it, as it doesn’t become active when clicked.

I have got it semi-working with a hacky workaround by comparing the column in data to data previous, which stops anything else causing an update, but unfortunately I still get the unwanted behaviour of one second of loading bars before the table reappears, unchanged, with a PreventUpdate. I’m not sure if I can prevent this… if anyone has any ideas, that would be great… however, I think column-level callbacks would be a good addition.

Hey @plantedsneeze

Why don’t you use two different data tables, the first one at the left with only one column and the second in the rigth with the rest, then your callback only fires if the first table is changed, but get as input and output the data from both :grinning: