Dash: Submit form.

Created on 22 Jun 2017  路  4Comments  路  Source: plotly/dash

What is the advised way to submit form data through a button click?

Most helpful comment

There are two concepts that are in Beta for doing this: Events and State. I haven't documented them yet because I'm not confident yet that Events is the correct abstraction. For now, you can see an example here on how they work: https://gist.github.com/chriddyp/e546a2a2c05df29c868e4cef57fb2105, but just know that this _may_ change in the future.

In the short term, I'm planning on adding "click stateto every component, an attribute that is something liken_clicks`. Then, you could subscribe to that change with something like:

@dash.dependencies(Output(...), [Input('my-button', n_clicks')])
def update_on_click(number_of_times_the_button_has_been_clicked):
    return ...

If you knew the number of times the button has been clicked, you could even do something like toggle things on and off depending on whether n_clicks was even or odd.

All 4 comments

There are two concepts that are in Beta for doing this: Events and State. I haven't documented them yet because I'm not confident yet that Events is the correct abstraction. For now, you can see an example here on how they work: https://gist.github.com/chriddyp/e546a2a2c05df29c868e4cef57fb2105, but just know that this _may_ change in the future.

In the short term, I'm planning on adding "click stateto every component, an attribute that is something liken_clicks`. Then, you could subscribe to that change with something like:

@dash.dependencies(Output(...), [Input('my-button', n_clicks')])
def update_on_click(number_of_times_the_button_has_been_clicked):
    return ...

If you knew the number of times the button has been clicked, you could even do something like toggle things on and off depending on whether n_clicks was even or odd.

The example does not work - there is an error in line 52 -

NameError: global name 'go' is not defined

The idea of being able to access the state of a giving component aligns pretty well with how React handles things like this. Or maybe, there could be a "redux store" could be accessed at any point by any function.

now documented in https://plot.ly/dash/state

Was this page helpful?
0 / 5 - 0 ratings