一、学习内容
巩固Python Dash(三)的学习内容,自行撰写类似网页。
二、代码
# author : 高冷男孩不吃苹果
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
textarea = dcc.Textarea(value="", id="text",style={"width":"100%","height":"10rem"}) #组件,与Input类似,输入区域大
markdown = dcc.Markdown("",id="mark")
app.layout = html.Div([
markdown,
html.H3("输入文字"),
html.Hr(), #画一条横线
textarea
])
#(第一种方法)
# def rule(value):
# return value
# data_processer = app.callback(
# Output(component_id="mark", component_property="children"),
# [Input(component_id="text", component_property="value")]
# )
# data_processer(rule)
#(第二种方法)
@app.callback(
Output("mark", "children"),
Input("text", "value")
)
def f(value):
return value
app.run_server(debug=True)
三、运行结果
点击右下角Callbacks按钮可查看数据流向