callback ex – sidebar to breadcrumbs

Published onesixx on

MENU_ITEMS = ("home", "basic_cards", "social_cards", "tab_cards",)
menus = [(f"{menu}", f"/{menu}") for menu in MENU_ITEMS]

import dash
from dash.exceptions import PreventUpdate

# @app.callback(
#     Output('mybread', 'text'),
#     [Input('menu_home', 'n_clicks'),
#      Input('menu_basic_cards', 'n_clicks'),
#      Input('menu_social_cards', 'n_clicks'),
#      Input('menu_tab_cards', 'n_clicks'),],
#     [State('menu_home', 'label'),
#      State('menu_basic_cards', 'label'),
#      State('menu_social_cards', 'label'),
#      State('menu_tab_cards', 'label'),])
@app.callback(
    Output('mybread', 'text'),
    [ Input(f"menu_{menu}", "n_clicks") for menu in MENU_ITEMS],
    [ State(f"menu_{menu}", "label")    for menu in MENU_ITEMS] )
# def update_breadcrumbs(*arg):
def update_breadcrumbs( 
    nClick1, nClick2, nClick3, nClick4,
    home, basic_cards, social_cards, tab_cards,):
    ctx = dash.callback_context
    if not ctx.triggered:
        raise PreventUpdate
    else:
        input_id = ctx.triggered[0]['prop_id'].split('.')[0].split('_', maxsplit=1)[1]
    return eval(input_id)

oooo

# def activate(input_id, 
#     home, basic_cards, social_cards, tab_cards,):
#     menu_n = len(MENU_ITEMS)
#     menu_status = [ False for i in range(menu_n)]
#     try:    
#         menu_idx = MENU_ITEMS.index(input_id.split( '_', maxsplit=1)[1])    
#         menu_status[menu_idx]=True
#     except:
#         pass
#     return menu_status

# @app.callback([Output(f"content_{menu}", "active") for menu in MENU_ITEMS],
#               [ Input(f'menu_{menu}', 'n_clicks') for menu in MENU_ITEMS])
# def activate_tab(
#     home, basic_cards, social_cards, tab_cards,):
#     ctx = dash.callback_context
#     if not ctx.triggered:
#         raise PreventUpdate
#     else:
#         input_id = ctx.triggered[0]['prop_id'].split('.')[0] 
#     return activate(input_id, 
#         home, basic_cards, social_cards, tab_cards,)
    
Categories: dash

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x