Issue
I have an input and a button, I need to save the value of the text input when the button is pressed .
dcc.Input(id='username', value='Initial Value', type='text'),
html.Button(id='submit-button', children='Submit'),
I am missing something from my callback?
@app.callback(Output('output_div','children' ),
[Input('submit-button')],
[State('input-element', 'value')],
[Event('submit-button', 'click'])
def update_output(input_element):
print(input_element)
Thanks
Solution
Minimal working example:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Output, State, Input
if __name__ == '__main__':
app = dash.Dash()
app.layout = html.Div([
dcc.Input(id='username', value='Initial Value', type='text'),
html.Button(id='submit-button', type='submit', children='Submit'),
html.Div(id='output_div')
])
@app.callback(Output('output_div', 'children'),
[Input('submit-button', 'n_clicks')],
[State('username', 'value')],
)
def update_output(clicks, input_value):
if clicks is not None:
print(clicks, input_value)
app.run_server(host='0.0.0.0')
For further information, you can take a look to this answer or this one. If you are interested in handling enter event also, you can find some useful hints in this thread.
Answered By - PieCot
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.