How to get the filtered pandas dataframe from a dash_table.DataTable

How do I get a pandas dataframe from a dash_table.DataTable after using the table’s filter controls to filter the data?

In your callback, use Input(‘table-id’, ‘derived_viewport_data’).

Thanks klamike,

That’s almost what I need. I want to get all of the filtered data, not just what is shown in the “viewport”. See in the picture below, I have prev and next buttons, so only some of the data is displayed at a time, but I want to plot all of the data.

Also, do you know what type of format the callback “Input(‘table-id’, ‘derived_viewport_data’)” returns? Here is a sample of the output that I get back:

[{‘Optical Output Power (W)’: 0.0002683861, ‘Power Meter Head’: ‘S302C,090679,06-Aug-2009,2,2,33’, ‘Bias DAC Value’: 0, ‘Mod DAC POR’: 0, ‘Mod DAC Value’: 350, ‘Xpoint Control Reg’: 129, ‘Xpoint Switch Reg’: 255, ‘Bus Voltage
(V)’: 10.02875, ‘Shunt Voltage (V)’: 0.000365, ‘Bus Current (A)’: 0.0608, ‘Bus Power (W)’: 0.615, ‘Temp A (°C)’:
0, ‘Temp B (°C)’: 41.5, ‘Amb Light Ch0’: 0, ‘Amb Light Ch1’: 0, ‘Timebase_Scale’: 4e-09, ‘sample_rate’: 10000000000, ‘Modulation_Frequency_(Hz)’: 50000000, ‘integration_time (s)’: 0.004, ‘dead_time (s)’: 0.004}, {‘Optical Output Power (W)’: 0.000269416, ‘Power Meter Head’: ‘S302C,090679,06-Aug-2009,2,2,33’, ‘Bias DAC Value’: 0, ‘Mod DAC
POR’: 0, ‘Mod DAC Value’: 350, ‘Xpoint Control Reg’: 129, ‘Xpoint Switch Reg’: 255, ‘Bus Voltage (V)’: 10.03, ‘Shunt Voltage (V)’: 0.00036, ‘Bus Current (A)’: 0.06, ‘Bus Power (W)’: 0.61, ‘Temp A (°C)’: 0, ‘Temp B (°C)’: 41.5, ‘Amb Light Ch0’: 0, ‘Amb Light Ch1’: 0, ‘Timebase_Scale’: 0.0016, ‘sample_rate’: 5000000, ‘Modulation_Frequency_(Hz)’: 50000000, ‘integration_time (s)’: 0.004, ‘dead_time (s)’: 0.004}, {‘Optical Output Power (W)’: 0.0002009706, ‘Power Meter Head’: ‘S302C,090679,06-Aug-2009,2,2,33’, ‘Bias DAC Value’: 0, ‘Mod DAC POR’: 0, ‘Mod DAC Value’: 340, ‘Xpoint Control Reg’: 129, ‘Xpoint Switch Reg’: 255, ‘Bus Voltage (V)’: 10.02625, ‘Shunt Voltage (V)’: 0.00035000000000000005, ‘Bus Current (A)’: 0.0584, ‘Bus Power (W)’: 0.59, ‘Temp A (°C)’: 0, ‘Temp B (°C)’: 42, ‘Amb Light Ch0’: 0, ‘Amb Light Ch1’: 0, ‘Timebase_Scale’: 1e-08, ‘sample_rate’: 10000000000, ‘Modulation_Frequency_(Hz)’: 20000000, ‘integration_time (s)’: 0.004, ‘dead_time (s)’: 0.004}, {‘Optical Output Power (W)’: 0.0002013668, ‘Power Meter Head’: ‘S302C,090679,06-Aug-2009,2,2,33’, ‘Bias DAC Value’: 0, ‘Mod DAC POR’: 0, ‘Mod DAC Value’: 340, ‘Xpoint Control Reg’: 129, ‘Xpoint Switch Reg’: 255, ‘Bus Voltage (V)’: 10.02625, ‘Shunt Voltage (V)’: 0.000357, ‘Bus Current (A)’: 0.0596, ‘Bus Power (W)’: 0.6000000000000001, ‘Temp A (°C)’: 0, ‘Temp B (°C)’: 42, ‘Amb Light Ch0’: 0, ‘Amb Light Ch1’: 0, ‘Timebase_Scale’: 0.0016, ‘sample_rate’: 5000000, ‘Modulation_Frequency_(Hz)’: 20000000, ‘integration_time (s)’: 0.004, ‘dead_time (s)’: 0.004}, {‘Optical Output Power (W)’: 0.0007006057, ‘Power Meter Head’: ‘S302C,090679,06-Aug-2009,2,2,33’, ‘Bias DAC Value’: 0, ‘Mod DAC POR’: 0, ‘Mod DAC Value’: 450, ‘Xpoint Control Reg’: 129, ‘Xpoint Switch Reg’: 255, ‘Bus Voltage (V)’: 10.03875, ‘Shunt Voltage (V)’: 0.000998, ‘Bus
Current (A)’: 0.16620000000000001, ‘Bus Power (W)’: 1.67, ‘Temp A (°C)’: 0, ‘Temp B (°C)’: 59.5, ‘Amb Light Ch0’: 0, ‘Amb Light Ch1’: 0, ‘Timebase_Scale’: 2.5e-09, ‘sample_rate’: 10000000000, ‘Modulation_Frequency_(Hz)’: 80000000, ‘integration_time (s)’: 0.004, ‘dead_time (s)’: 0.004}, {‘Optical Output Power (W)’: 0.0006921293, ‘Power Meter Head’: ‘S302C,090679,06-Aug-2009,2,2,33’, ‘Bias DAC Value’: 0, ‘Mod DAC POR’: 0, ‘Mod DAC Value’: 450, ‘Xpoint Control Reg’: 129, ‘Xpoint Switch Reg’: 255, ‘Bus Voltage (V)’: 10.0375, ‘Shunt Voltage (V)’: 0.000998, ‘Bus Current (A)’: 0.16620000000000001, ‘Bus Power (W)’: 1.665, ‘Temp A (°C)’: 0, ‘Temp B (°C)’: 59.5, ‘Amb Light Ch0’:
0, ‘Amb Light Ch1’: 0, ‘Timebase_Scale’: 0.0016, ‘sample_rate’: 5000000, ‘Modulation_Frequency_(Hz)’: 80000000, ‘integration_time (s)’: 0.004, ‘dead_time (s)’: 0.004}, {‘Optical Output Power (W)’: 0.0005883522000000001, ‘Power Meter Head’: ‘S302C,090679,06-Aug-2009,2,2,33’, ‘Bias DAC Value’: 0, ‘Mod DAC POR’: 0, ‘Mod DAC Value’: 380, ‘Xpoint Control Reg’: 129, ‘Xpoint Switch Reg’: 255, ‘Bus Voltage (V)’: 10.06625, ‘Shunt Voltage (V)’: 0.00054, ‘Bus Current (A)’: 0.09, ‘Bus Power (W)’: 0.905, ‘Temp A (°C)’: 0, ‘Temp B (°C)’: 49, ‘Amb Light Ch0’: 0, ‘Amb Light
Ch1’: 0, ‘Timebase_Scale’: 4e-09, ‘sample_rate’: 10000000000, ‘Modulation_Frequency_(Hz)’: 50000000, ‘integration_time (s)’: 0.004, ‘dead_time (s)’: 0.004}, {‘Optical Output Power (W)’: 0.0005919171, ‘Power Meter Head’: ‘S302C,090679,06-Aug-2009,2,2,33’, ‘Bias DAC Value’: 0, ‘Mod DAC POR’: 0, ‘Mod DAC Value’: 380, ‘Xpoint Control Reg’: 129, ‘Xpoint Switch Reg’: 255, ‘Bus Voltage (V)’: 10.067501, ‘Shunt Voltage (V)’: 0.000513, ‘Bus Current (A)’: 0.0854, ‘Bus Power (W)’: 0.865, ‘Temp A (°C)’: 0, ‘Temp B (°C)’: 49, ‘Amb Light Ch0’: 0, ‘Amb Light Ch1’: 0, ‘Timebase_Scale’: 0.0016, ‘sample_rate’: 5000000, ‘Modulation_Frequency_(Hz)’: 50000000, ‘integration_time (s)’: 0.004,
‘dead_time (s)’: 0.004}, {‘Optical Output Power (W)’: 0.00026513810000000003, ‘Power Meter Head’: ‘S302C,090679,06-Aug-2009,2,2,33’, ‘Bias DAC Value’: 0, ‘Mod DAC POR’: 0, ‘Mod DAC Value’: 400, ‘Xpoint Control Reg’: 129, ‘Xpoint Switch Reg’: 255, ‘Bus Voltage (V)’: 10.03375, ‘Shunt Voltage (V)’: 0.000707, ‘Bus Current (A)’: 0.1178, ‘Bus
Power (W)’: 1.185, ‘Temp A (°C)’: 0, ‘Temp B (°C)’: 56, ‘Amb Light Ch0’: 0, ‘Amb Light Ch1’: 1, ‘Timebase_Scale’: 1.8e-09, ‘sample_rate’: 10000000000, ‘Modulation_Frequency_(Hz)’: 110000000, ‘integration_time (s)’: 0.004, ‘dead_time (s)’: 0.004}, {‘Optical Output Power (W)’: 0.0002669602, ‘Power Meter Head’: ‘S302C,090679,06-Aug-2009,2,2,33’, ‘Bias DAC Value’: 0, ‘Mod DAC POR’: 0, ‘Mod DAC Value’: 400, ‘Xpoint Control Reg’: 129, ‘Xpoint Switch Reg’: 255, ‘Bus Voltage (V)’: 10.03375, ‘Shunt Voltage (V)’: 0.000717, ‘Bus Current (A)’: 0.11960000000000001, ‘Bus Power (W)’: 1.2, ‘Temp A (°C)’: 0, ‘Temp B (°C)’: 56, ‘Amb Light Ch0’: 0, ‘Amb Light Ch1’: 1, ‘Timebase_Scale’: 0.0016, ‘sample_rate’: 5000000, ‘Modulation_Frequency_(Hz)’: 110000000, ‘integration_time (s)’: 0.004, ‘dead_time (s)’: 0.004}]

Thanks!

I’m displaying a df using df.to_dict(‘records’) so derived_viewport_data gives me:

[[{row1}, {row2}, {row3}]] where the keys of each row are the columns and the values are the corresponding values for the key column in that row.

This may vary, though. Best way to tell would be to pprint it.

@klamike @2goat2 To get all the filtered/sorted data, not limited to the current viewport, use derived_virtual_data instead.

2 Likes

Thanks @Marc-Andre and @klamike, it’s working!

I used pd.DataFrame.from_dict(data) to convert the dictionary format to a pandas data frame, and the derived_virtual_data in the callback to get all of the data in the table.

Thanks!