首页编程开发Dash3.使用callback实...

3.使用callback实现动态交互元素

main.py文件代码:

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

app = dash.Dash(__name__)

textarea = dcc.Textarea(value="",id="textrea",style={"width":"100%","height":"8rem"})
markdown = dcc.Markdown(children="",id="markdown")

app.layout = html.Div([
    markdown,
    html.H1("输入markdown格式内容:"),
    html.Hr(),
    textarea
])

@app.callback(
    Output("markdown","children"),
    [Input("textrea","value")]
)
def update(value):
    return value

app.run_server(debug=True)

创建一个style.css文件来设置网页样式:

body{
    background-color: #ffdeae;
}

运行代码,浏览器打开http://127.0.0.1:8050/,显示效果如下所示:

在输入框中输入markdown语法内容,显示效果如下所示:

RELATED ARTICLES

欢迎留下您的宝贵建议

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments