Advanced callbacks why is one output getting ignored ? (Docs example)

Hi there,

i saw an example here

app.layout = html.Div([
    html.P('Enter a composite number to see its prime factors'),
    dcc.Input(id='num', type='number', debounce=True, min=2, step=1),
    html.P(id='err', style={'color': 'red'}),

    Output('out', 'children'),
    Output('err', 'children'),
    Input('num', 'value')
def show_factors(num):
    if num is None:
        # PreventUpdate prevents ALL outputs updating
        raise dash.exceptions.PreventUpdate

    factors = prime_factors(num)
    if len(factors) == 1:
        # dash.no_update prevents any single output updating
        # (note: it's OK to use for a single-output callback too)
        return dash.no_update, '{} is prime!'.format(num)

    return '{} is {}'.format(num, ' * '.join(str(n) for n in factors)), ''

When i interact with the input, i can see that i get for 20 the whole sentence from the last return. In this case the output with the id = ‘err’ gets ignored. Why is that so? Shouldn’t i see the sentence displayed two times?

Shouldn’t that output update as well?

And how does dash.no_update work? How did it know to ignore the id=‘err’ ?

Hit enter.

Hitting enter sadly didn’t change anything :S

When i do insert a prime number and the if condition len(factors)==1 is true, then i get an err message and the ‘out’ stays as it is.

What i also don’t understand is why the ‘err’ message gets removed if i now insert a non prime number. Shouldn’t it receive the last return statement and update itself as well?

If you mean that you don’t want this err msg to be displayed at the same time as the previous Output, then remove dash.no_update.

thanks for the quick reply stu. I mean that i expected when typing 6, 2 divs showing 6is 2*3, but as soon as i type a non prime number i get only one div although the output should also appear on the err div since two outputs are declared in the callback decorator.

This actually returns a list with two values.
dash.no_update just doesn’t replace the previous value.

That was the culprit. Thank you!!!

My eyes completely dismissed the second argument.