我有一个输入和一个按钮,当按钮被按下时,我需要保存文本输入的值。
dcc.Input(id='username', value='Initial Value', type='text'),
html.Button(id='submit-button', children='Submit'),我的回调中遗漏了什么吗?
@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)谢谢
发布于 2018-07-28 03:07:30
最小工作示例:
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')有关更多信息,您可以查看this answer或this one。如果您也对处理enter事件感兴趣,您可以在this thread中找到一些有用的提示。
https://stackoverflow.com/questions/51407191
复制相似问题