首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >函数如何使用python在Dash中重新生成正确的参数?

函数如何使用python在Dash中重新生成正确的参数?
EN

Stack Overflow用户
提问于 2021-07-30 06:46:31
回答 1查看 78关注 0票数 0

我有一个关于使用python在dash中做函数的问题。

下面是我正在研究的代码:

代码语言:javascript
运行
AI代码解释
复制
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div([
    html.H6("Change the value in the text box to see callbacks in action!"),
    html.Div(["Input: ",
              dcc.Input(id='my-input', value='initial value', type='text')]),
    html.Br(),
    html.Div(id='my-output'),

])


@app.callback(
    Output(component_id='my-output', component_property='children'),
    Input(component_id='my-input', component_property='value')
)
def update_output_div(input_value):
    return 'Output: {}'.format(input_value)


if __name__ == '__main__':
    app.run_server(debug=True)

在回调之后,我们有一个函数"update_output_div“和一个名为" input_value”的参数,但是代码如何知道输入是名为“my-input_value”的输入呢?这个问题的第一个答案是因为顺序,但在本例中:

代码语言:javascript
运行
AI代码解释
复制
@app.callback(
    [Output(component_id='plot1', component_property='children'),
    Output(component_id='plot2', component_property='children'),
    Output(component_id='plot3', component_property='children'),
    Output(component_id='plot4', component_property='children'),
    Output(component_id='plot5', component_property='children')],
    [Input(component_id='input-type', component_property='value'),
    Input(component_id='input-year', component_property='value')],
    # REVIEW4: Holding output state till user enters all the form information. In this case, it will be chart type and year
    [State("plot1", 'children'), State("plot2", "children"),
    State("plot3", "children"), State("plot4", "children"),
    State("plot5", "children")])

# Add computation to callback function and return graph
def get_graph(chart, year, children1, children2, c3, c4, c5):
EN

回答 1

Stack Overflow用户

发布于 2021-07-30 06:51:35

它尊重一个命令:

第一个输入component_property将作为函数的第一个参数,例如:

代码语言:javascript
运行
AI代码解释
复制
@app.callback(
    Output(component_id='my-output', component_property='children'),
    Input(component_id='my-input1', component_property='value1'),
    Input(component_id='my-input2', component_property='value2'),
    Input(component_id='my-input3', component_property='value3'),
    State(component_id='my-input4', component_property='value4'),
    State(component_id='my-input5', component_property='value5')
)
def update_output_div(value1, value2, value3, value4, value5):
    return func(value1, value2, value3, value4, value5)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68592938

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档