Create callback using for loop


my dash app has multiple graph (each scene has 1 graph), i would like to create a callback for each graph using the same input. can i use for loop to do so?

for scene in scenarios:
    dash.dependencies.Output(f'trend-{scene}', 'figure'),
    [dash.dependencies.Input('select-block', 'value')]
  def update_figure(block)

i just want to clarify my problem statement.
i am creating an apps which contain 10 graphs for each scenario with similar callback input. instead of creating the 10 function which is troublesome i wish i can do a function factory kind of implementation. do you have any idea how to achieve it?

This is part of my code, i have function factory called “func_factory_4_timing_trend” and i want to create a callback function for each corner.

for corner in corners:
        dash.dependencies.Output('trend-{corner}', 'figure'),
        [dash.dependencies.Input('select-par', 'value')]

it return as an error =.=
SyntaxError: invalid syntax

that is because you need to define a function.

This thread should be helpful with your issue.


thanks. i decided to lump everything into a big callback function :slight_smile:

1 Like