Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

"Click" Function in Button Config Not Defined

$
0
0

@Zach wrote:

Hi,

I’m running into an issue where clicking a button for the second time throws a JavaScript error.
I’m trying to make a function that takes the children of a row and a figure in storage, appends that figure to the children, and returns the appended children.
Right now I have this callback function:

@app.callback(
    Output('row-container', 'children'),

    [Input('append-button', 'n_clicks'),
     Input('fig-store', 'data')],
    [State('row-container', 'children')]
)
def update_row(n_clicks, stored_fig, current_figs):
    """ Duplicates the contents of a row and appends that to itself

    Parameters
    -------------
    n_clicks : Int, None
        The number of times the button is pressed
    stored_fig : go.Figure, None
        The first figure in the row (in local storage)
    current_figs : List, None
        The children of the row that is currently displayed on the page

    Returns
    ---------
    new_children : List
        current_figs with stored_fig appended to it
    """

    # If the figures are currently on the screen:
    if current_figs:
        new_children = current_figs
    else:
        new_children = []

    # If the button was pressed and the stored figure exists
    if n_clicks and stored_fig:
        new_children.append(stored_fig)
    elif stored_fig:  # The stored_fig changed
        new_children = [stored_fig]

    return new_children

This works just fine the first time I press that append-button and it appends the stored_fig to the children. However, the second time I press the button I get this error:

From looking deeper with ipdb, it looks like new_children is properly updated and returned but somewhere deep in Dash a bad response is thrown. Here’s what Chrome’s console has to say about it:

Uncaught Error: must provide button 'click' function in button config
    at l.c.createButton (plotly-1.49.4.min.js:7)
    at plotly-1.49.4.min.js:7
    at Array.forEach (<anonymous>)
    at plotly-1.49.4.min.js:7
    at Array.forEach (<anonymous>)
    at l.c.updateButtons (plotly-1.49.4.min.js:7)
    at l.c.update (plotly-1.49.4.min.js:7)
    at new l (plotly-1.49.4.min.js:7)
    at e.exports (plotly-1.49.4.min.js:7)
    at Object.e.exports [as manage] (plotly-1.49.4.min.js:7)

That l.c.createButton line is:

Do y’all know what’s going on here? I’m not sure why the click function isn’t defined for a button, why the button works the first time, or why createButton is even being called.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 6271

Trending Articles