Multiples Callbacks

There’s a way to set one callback from multiples ids?

Something like this …

@app.callback(
[Output('lista-de-datas', 'data'),
Output('lista-de-datas', 'value'),
Output('lista-de-datas', 'disabled'),
Input('lista-de-modelos', 'value')],

[Output('lista-de-datas2', 'data'),
Output('lista-de-datas2', 'value'),
Output('lista-de-datas2', 'disabled'),
Input('lista-de-modelos2', 'value')]
)

def choice_date(value):
.....

For now i’m using multiple callbacks to do the samething …

@app.callback(
Output('lista-de-datas', 'data'),
Output('lista-de-datas', 'value'),
Output('lista-de-datas', 'disabled'),
Input('lista-de-modelos', 'value')
)
def choice_date(value):

    if 'MERGE' not in value:

        dirs = os.listdir(f'{FTP_PREFIX}/{value.lower()}')
        dirs = [pd.to_datetime(x, format='%Y%m%d%H') for x in dirs]
        dirs = sorted(dirs, reverse=True)
        dirs = [x.strftime('%d/%m/%Y %H UTC') for x in dirs]
        dirs = [{'value': x, 'label': x} for x in dirs]

        return dirs, dirs[0]['value'], False

    else:

        ini = ['-']
        variavel = 'Precipitação acumulada em 24 hr'

        return ini, variavel, True


#######################################################################################

@app.callback(
Output('lista-de-datas2', 'data'),
Output('lista-de-datas2', 'value'),
Output('lista-de-datas2', 'disabled'),
Input('lista-de-modelos2', 'value')
)
def choice_date(value):

    if 'MERGE' not in value:

        dirs = os.listdir(f'{FTP_PREFIX}/{value.lower()}')
        dirs = [pd.to_datetime(x, format='%Y%m%d%H') for x in dirs]
        dirs = sorted(dirs, reverse=True)
        dirs = [x.strftime('%d/%m/%Y %H UTC') for x in dirs]
        dirs = [{'value': x, 'label': x} for x in dirs]

        return dirs, dirs[0]['value'], False

    else:

        ini = ['-']
        variavel = 'Precipitação acumulada em 24 hr'

        return ini, variavel, True

Hi @jp123, that looks like a typical use case for pattern matching callbacks.

Your function signature would look like this:

@app.callback(
    Output({'type': 'lista-de-datas', 'index': MATCH}, 'data'),
    Output({'type': 'lista-de-datas', 'index': MATCH}, 'value'),
    Output({'type': 'lista-de-datas', 'index': MATCH}, 'disabled'),
    Input({'type': 'lista-de-modelos', 'index': MATCH}, 'value')

Hi @AIMPED

thanks.

When I try to do with your example,

@app.callback(
    Output({'type': 'lista-de-datas', 'index': MATCH}, 'data'),
    Output({'type': 'lista-de-datas', 'index': MATCH}, 'value'),
    Output({'type': 'lista-de-datas', 'index': MATCH}, 'disabled'),
    Input({'type': 'lista-de-modelos', 'index': MATCH}, 'value')

The callback stop to work.

The implementation is somenthing like this?

@app.callback(
    Output({'type': 'lista-de-datas', 'index': MATCH}, 'data'),
    Output({'type': 'lista-de-datas', 'index': MATCH}, 'value'),
    Output({'type': 'lista-de-datas', 'index': MATCH}, 'disabled'),
    Input({'type': 'lista-de-modelos', 'index': MATCH}, 'value')
)
def choice_date(value):

    if 'MERGE' not in value:

        dirs = os.listdir(f'{FTP_PREFIX}/{value.lower()}')
        dirs = [pd.to_datetime(x, format='%Y%m%d%H') for x in dirs]
        dirs = sorted(dirs, reverse=True)
        dirs = [x.strftime('%d/%m/%Y %H UTC') for x in dirs]
        dirs = [{'value': x, 'label': x} for x in dirs]

        return dirs, dirs[0]['value'], False

    else:

        ini = ['-']
        variavel = 'Precipitação acumulada em 24 hr'

        return ini, variavel, True

I’m not sure I get the concept

You could try with a small example with some buttons to understand the concept.

An other option could be sharing your code here and let us have a look.