-
2개 이상 Variable 의 callback 연결plotly dash 2022. 5. 29. 20:31
문제
A, B 숫자를 읽어 operand 에 따라 계산하도록 웹페이지를 개발
코드
from dash import Dash, html, dcc, Input, Output app = Dash() a_number = dcc.Input(id='input-a', value=0, type='number') b_number = dcc.Input(id='input-b', value=0, type='number') operator_radio = dcc.RadioItems(id='operator-radio', options={'plus': '+', 'minus': '-'}, value='plus') result_text = html.Div(id='output-text', children='Result: 0') app.layout = html.Div([ html.Label('A:'), a_number, html.Br(), html.Label('B:'), b_number, operator_radio, result_text ]) @app.callback( Output('output-text', 'children'), Input('input-a', 'value'), Input('input-b', 'value'), Input('operator-radio', 'value') ) def update_result(a, b, op): result = a + b if (op == 'plus') else a - b return f'Result: {result}' if __name__ == '__main__': app.run_server(debug=True)
참고: https://www.udemy.com/course/python-interactive-dashboards-with-plotly-dash
'plotly dash' 카테고리의 다른 글
Grid Layout (0) 2022.05.30 CSS 적용하기 (0) 2022.05.30 Callbacks with State (0) 2022.05.29 Chained Callback (0) 2022.05.29 Input callback 연결 (0) 2022.05.28