3

I added a button to my layout. When I try to write a callback for it, I get the following error:

dash.exceptions.NonExistantEventException: 
Attempting to assign a callback with
the event "click" but the component
"get_custom_vndr" doesn't have "click" as an event.

Here is a list of the available events in "get_custom_vndr":
[]

Here's how I'm adding it to my layout:

app_vndr.layout = html.Div([
    html.Button(
        '+',
        id='get_custom_vndr',
        type='submit'
    )
])

and here's the callback function that's giving the above error:

@app_vndr.callback(
    dash.dependencies.Output('overlay', 'className'),
    events=[dash.dependencies.Event('get_custom_vndr', 'click'),
            dash.dependencies.Event('add_vndr_id_submit', 'click')])
def show_input(b1_n, b2_n):    
    if b1_n>0:
        return ''
    elif b1_n>0:
        return 'hidden'

Did I miss something when I added the button to my layout? or when I tried to write the callback?

I got it working for

dash.dependencies.Input('get_custom_vndr', 'n_clicks')

but I'd like to use two buttons for the same output and with the n_clicks event, I'd need to try to figure out which button was clicked by comparing the current n_clicks to the previous n_clicks for each button, which seems like a pretty hacky way to do it.

1

2 Answers 2

1

Dash doens't allow multiple callback for the same Output()

0
-3

I am not really sure if I understood your question right, but see, if this helps...

but I'd like to use two buttons for the same output

Easy! Just define the explicit dash component as Output, followed by two buttons as Input. No matter, which buton is clicked, both of them will trigger the same function. Example:

@app.callback(
    dash.dependencies.Output('overlay', 'className'),
    [dash.dependencies.Input('button1', 'n_clicks'),
     dash.dependencies.Input('button2', 'n_clicks')])

def update_output(n_clicks1, n_clicks2):
    # This is, where the magic happens

and with the n_clicks event, I'd need to try to figure out which button was clicked

If you want to use two buttons for the same function and differ, which one is being used, separate the solution above into two functions:

@app.callback(
    dash.dependencies.Output('overlay', 'className'),
    [dash.dependencies.Input('button1', 'n_clicks')])

def update_output(n_clicks1):
    # This is, where the magic happens for button 1

@app.callback(
    dash.dependencies.Output('overlay', 'className'),
    [dash.dependencies.Input('button2', 'n_clicks')])

def update_output(n_clicks2):
    # This is, where the magic happens for button 2
2
  • 1
    Dash doesn't allow you to have two callbacks that update the same output. Otherwise, yeah, that would work really well. Commented Apr 9, 2018 at 15:21
  • I tried it this way and it looked like Dash could handle it
    – DrGamepad
    Commented Apr 10, 2018 at 8:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.