Im creating an accordion object which contains 3 levels, the date, the time (AM or PM) and a stock. There is a button within the last item which i would like to press in order for a plot to show up, however i am having no luck with the pattern matching callbacks. I am seeming to miss something with setting up the ids for my particular use case. Any help would be appreciated!
def nest_acc(date, edf):
market_stocks = stocks_on_specific_date
am_stocks = morning_stock_list_on_date
pm_stocks = afternoon_stock_list_on_date
fill_text = lambda x: dbc.Row([
dbc.Col(dcc.Markdown(f'''### ${x.upper()} ''')),
dbc.Col(f'''{info_file[x]['sector']}'''),
dbc.Col(dbc.Button("Show Plot", id = f'show_chart_button-{x}', n_clicks = 0, value = x))
])
text_plot = lambda x: [fill_text(x), html.Div(id = f'chart-{x}')]
am_acc = dbc.Accordion(
[dbc.AccordionItem(text_plot(stock), title=info_file[stock]['longName']) for stock in am_stocks],
flush = True,
start_collapsed = False
)
pm_acc = dbc.Accordion(
[dbc.AccordionItem(text_plot(stock), title=info_file[stock]['longName']) for stock in pm_stocks],
flush = True,
start_collapsed = True
)
out_acc = dbc.Accordion(
[dbc.AccordionItem(am_acc, title="π€οΈ AM"), dbc.AccordionItem(pm_acc, title="β
οΈ PM")],
start_collapsed=False,
flush = True,
)
return out_acc
exps = sorted(list(edf['Date'].dt.date.unique()))
nest_acc = dbc.Accordion(
[dbc.AccordionItem(nest_acc(d, edf), title= dt.datetime.strftime(d, format = "%a %b %d, %Y")) for d in exps],
flush = True,
start_collapsed = False
)
accordion = html.Div([nest_acc])
####################################################################################################
dash.register_page(__name__)
####################################################################################################
db_container= dbc.Container(
[
dbc.Row(
[
dbc.Col(accordion),
]
)
],
style=contain_style
)
chart_area = html.Div(id = 'em-chart')
layout = html.Div(
[
chart_area,
html.H1("π¨ Earnings ToolBox π οΈ" , style={'textAlign': 'center', 'marginTop': 40}),
db_container,
]
)
@callback(
Output('em-chart', 'children'),
[Input(f'show_chart_button-{x}', 'n_clicks') for x in market_stocks],
)
def lc(*args):
stock = ctx.triggered[0]['prop_id'].split('-')[1].split('.')[0]
# Do some plotting
return dcc.Graph(figure = fig)