@BigSteak4 wrote:
My default view is a datatable with a list of items. Each item has statistics associated with it - for example, max, min, stddev, etc… Because the statistics take a while to execute, they are disabled by default and only loaded if the user checks a checkbox to show statistics.
If the box is checked I load a second dataframe with the raw data, calculate the statistics, merge it with the master dataframe, then display that as a Dash datatable.
Several columns are formatted differently (some as currency, others a number, others a link, etc) so I cannot use the snippet of code from the documentation:
columns=[ {"name": i, "id": i} for i in sorted(df.columns) ],
If there is a column that exists in the columns= variable, but not in the dataframe, and error will occur.
I intend to have several other sources pulled from the database and merged into the master df in the same way as the stats data, so the columns being loaded/displayed will depend on what the user has selected.
What is the best way to format the resultant datatable columns if I am not sure which columns are going to exist in the final output? Is there a function that allows two separate datatables to be merged together?
If not, my thought is to have a dictionary with all possible column names and how they are formatted, and look this up during the call and format accordingly. I wasn’t sure if there was a better way to do this.
Posts: 2
Participants: 1