✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

How to take a a generated list and a value as Input in the same callback?

I have a set of buttons and a hidden-div that I want to take inputs from. I have managed to get the input from the buttons in the following way

@app.callback(
    [
        Output('league-table', 'children'),
    ],
    [
        Input(str(i), 'n_clicks') for i in df_teams['teams']

    ],
)
def update_league_table(*args):
    changed_id = [p['prop_id'] for p in dash.callback_context.triggered][0]
    print(changed_id)

But when trying to get the input from the dropdown component

@app.callback(
    [
        Output('league-table', 'children'),
    ],
    [
        [Input(str(i), 'n_clicks') for i in df_teams['teams']],
        Input('intermediate-year-dd', 'value')
    ],
)
def update_league_table(value, *args):
    changed_id = [p['prop_id'] for p in dash.callback_context.triggered][0]
    print(value)

I get the below error, which is because the the Inputs from the buttons get wrapped in a list. How can I get both the Input from when a button is clicked and from the hidden div at the same time?

dash.exceptions.IncorrectTypeException: The input argument `[<Input `Arsenal.n_clicks`>, <Input `Aston Villa.n_clicks`>, <Input `Bournemouth.n_clicks`>, <Input `Brighton.n_clicks`>, <Input `Burnley.n_clicks`>, <Input `Chelsea.n_clicks`>, <Input `Crystal Palace.n_clicks`>, <Input `Everton.n_clicks`>, <Input `Leicester.n_clicks`>, <Input `Liverpool.n_clicks`>, <Input `Man City.n_clicks`>, <Input `Man Utd.n_clicks`>, <Input `Newcastle.n_clicks`>, <Input `Norwich.n_clicks`>, <Input `Sheffield Utd.n_clicks`>, <Input `Southampton.n_clicks`>, <Input `Spurs.n_clicks`>, <Input `Watford.n_clicks`>, <Input `West Ham.n_clicks`>, <Input `Wolves.n_clicks`>]` must be of type `dash.dependencies.Input`.

Hi and welcome to Dash!

This syntax should get rid of that error message:

@app.callback(
    [
        Output('league-table', 'children'),
    ],
    
        [Input(str(i), 'n_clicks') for i in [df_teams['teams']]]
        +
        [Input('intermediate-year-dd', 'value')]
    
)

@AnnMarieW Thank you for your reply! One small remark is that the parenthesis are not balanced and I’m a bit unsure how they should be balanced. Could you kindly clarify on that? Thank you for taking your time!

I updated the original to include the missing ]
:slight_smile:

Thank you, that solved the syntax problem! Now I only have to deal with the new error messages that raised from solving this one :smile:

AnnMarieW helped me solve the problem, with magic syntax! Since a list of Input is already generated for all the buttons, more inputs can be added to that list by first converting them to a list and appending them to the list by adding the list toghether with a +.

@app.callback(

    Output('league-table', 'children'),


    [Input('intermediate-year-dd', 'children')]
    +
    [Input(str(i), 'n_clicks') for i in df_teams['teams']]
        
)

def update_league_table(value, *args):
    changed_id = [p['prop_id'] for p in dash.callback_context.triggered][0]