実際に、彼らはのために利用できるクリックイベントを持っています最新のdash_html_components
のボタンですが、まだ完全には文書化されていないようです。作成者のchriddypは、Event
オブジェクトが将来保証されない可能性がありますが、State
はそうでなければならないstatedです。
使用State
が好き:
@app.callback(
Output('output', 'children'),
[Input('button-2', 'n_clicks')],
state=[State('input-1', 'value'),
State('input-2', 'value'),
State('slider-1', 'value')])
あなたは彼らが変更された場合、コールバックを開始せずに、入力として値を使用することができます - 代わりにコールバックをオフに解雇しInput('button', 'n_clicks')
を待っています。
import dash
from dash.dependencies import Input, Output, State
import dash_html_components as html
import dash_core_components as dcc
app = dash.Dash()
app.layout = html.Div([
html.Button('Click Me', id='button'),
html.H3(id='button-clicks'),
html.Hr(),
html.Label('Input 1'),
dcc.Input(id='input-1'),
html.Label('Input 2'),
dcc.Input(id='input-2'),
html.Label('Slider 1'),
dcc.Slider(id='slider-1'),
html.Button(id='button-2'),
html.Div(id='output')
])
@app.callback(
Output('button-clicks', 'children'),
[Input('button', 'n_clicks')])
def clicks(n_clicks):
return 'Button has been clicked {} times'.format(n_clicks)
@app.callback(
Output('output', 'children'),
[Input('button-2', 'n_clicks')],
state=[State('input-1', 'value'),
State('input-2', 'value'),
State('slider-1', 'value')])
def compute(n_clicks, input1, input2, slider1):
return 'A computation based off of {}, {}, and {}'.format(
input1, input2, slider1
)
if __name__ == '__main__':
app.run_server(debug=True)
:リンクから以下の完全なコード例をコピー