Hi @dilfin07
Using the example of the link and changing your code to generate the DataFrame I acomplished what you need, I shure there must exist a better solution, but it works:
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import pandas as pd
import dash_table
from itertools import groupby
data =[
{'A': {'ABC': '1234', 'QWE': '2342'}},
{'B': {'ABC': '234', 'QWE': '3424', 'RTY': 'qwert'}},
{'A': {'ABC': '2342', 'QWE': '23424'}},
{'B': {'ABC': '2342', 'QWE': '23442', 'RTY': 'tree'}},
{'A': {'ABC': '2344', 'QWE': '3424'}},
{'B': {'ABC': '2344', 'QWE': '2344', 'RTY': 'awed'}}
]
data2 = [[k2+k, v2] for d in data for k,v in d.items() for k2,v2 in v.items()]
res = pd.DataFrame({k: [x[1] for x in g]
for k,g in groupby(sorted(data2), key=lambda x: x[0])})
app = dash.Dash(__name__)
app.layout = html.Div(children=[
html.H1(children='Hello Dash'),
dash_table.DataTable(
columns=[
{"name": ["A", "ABC"], "id": "ABCA"},
{"name": ["A", "QWE"], "id": "QWEA"},
{"name": ["B", "ABC"], "id": "ABCB"},
{"name": ["B", "QWE"], "id": "QWEB"},
{"name": ["B", "RTY"], "id": "RTYB"},
],
data =res.to_dict('records'),
merge_duplicate_headers=True,
)
])
if __name__ == '__main__':
app.run_server(debug=True)
As I’m not a code expert in using things like { k, v, i, etc } for … I’ll let you the part of generating a variable that bild the columns property as shown in the code taking the information from your data.
This is the table generated with this code: