query_list = []
for query_name, query_string in analytics_dict.items():
query_list.append({'query_name': query_name, 'query_string': query_string})
print(query_list)
layout = html.Div(children=[])
count = 1
for query in query_list:
query_name = query['query_name']
query_string = query['query_string']
# execute query and store result in a dataframe
df = pd.read_sql(query_string, engine)
# create a table component for the query result
table = dash_table.DataTable(
id=query_name,
columns=[{"name": i, "id": i} for i in df.columns],
data=df.to_dict("rows"),
page_action='native',
page_current=0,
page_size=10,
filter_action="native",
export_format="csv",
# style_data={
# 'whiteSpace': 'normal',
# 'height': 'auto',
# 'overflow': 'hidden'
# },
)
card = dbc.Card(
[
dbc.CardBody(table)
]
)
# create an accordion component for the query
accordion = dbc.Accordion(
id=f"accordion-{query_name}",
children=[
dbc.AccordionItem(
title=str(count) + ". " + query_name,
children=[card],
className="custom-accordion-item",
)
],
start_collapsed=True,
style={'width': '80%', 'border': '1px solid black', 'align': 'center', 'justify': 'center',
'margin-left': '10%'},
)
# add the accordion to the layout
layout.children.append(accordion)
count = count + 1
What i am trying to build is i am making a list of query_name and their query_string(in sql) and i am creating accordions for each and displaying the table created by the sql query inside the accordion. But due to this my page loads very slowly as there are many queries running simultaneously. I want the dataframe to be made only after i click on the particular accordion. so that the page loads faster. I have tried creating callbacks but failed . Can anyone help me with this ?