在破折号中使用按钮功能

using button feature in dash

我目前有一个 dash 应用程序,它使用 5 个用户输入的回调来打印某些功能。代码如下。

我想做的是,与其让用户调整一项功能,然后让功能自动打印整套功能,不如让用户能够调整没有功能打印的任何或所有功能,然后可以点击提交按钮打印所有新调整的功能。

如您所见,我试了一下,但没有用。

app = dash.Dash()
app.layout = html.Div(children=[
    html.H1(children='Regression Analyzer for Individual Market Securities', style={'textAlign': 'center'
        }),
   
    dcc.DatePickerRange(
        id = 'my-date',
        min_date_allowed=date(2015, 1, 1),
        max_date_allowed=date(2020, 11, 11),
        initial_visible_month=date(2017, 8, 5),
        start_date=date(2015, 1, 1),
        end_date=date(2020, 11, 1)),
        
    dcc.Dropdown(id = 'MA',
    options=[
        {'label': 'Day Average', 'value': 'Day Average'},
        {'label': '7 Day Avg', 'value': '7 Day Avg'},
        {'label': '50 Day Avg', 'value': '50 Day Avg'},
        {'label': '200 Day Avg', 'value': '200 Day Avg'}
    ], value='Day Average'),
        
    dcc.Input(id = 'Name',
    placeholder='Enter stock ticker ...',
    type='text',
    value='AAPL'),
    
    html.Button('Submit', id='submit-val', n_clicks=0),
    
    dcc.Loading(
    dcc.Graph(id='figure-scatter'),
    type='cube',
    color='#f15d27'),
    
    dcc.Loading(
    dcc.Graph(id='figure-regression'),
    type='cube',
    color='#f15d27'),
    
    dcc.Loading(
    dcc.Graph(id='figure-table'),
    type='cube',
    color='#f15d27'),
    
    html.Div(id='my-output')
    
    ])

@app.callback(Output(component_id='figure-scatter', component_property='figure'),
    [dash.dependencies.Input('submit-val', 'n_clicks')]
    [dash.dependencies.State("Name", "value"),
     dash.dependencies.State("MA", "value"),
     dash.dependencies.State("my-date", "start_date"),
     dash.dependencies.State("my-date", "end_date")] )
def compare_to_market1(Name, MA, start_date, end_date):
    print(Name, MA, start_date, end_date)

你的回调有 1 个输入和 4 个状态,所以函数应该有 5 个参数,但它只有 4 个,就像你写的那样。它应该是这样的:

@app.callback(Output(component_id='figure-scatter', component_property='figure'),
    [dash.dependencies.Input('submit-val', 'n_clicks')]
    [dash.dependencies.State("Name", "value"),
     dash.dependencies.State("MA", "value"),
     dash.dependencies.State("my-date", "start_date"),
     dash.dependencies.State("my-date", "end_date")] )
def compare_to_market1(submit_click, Name, MA, start_date, end_date):
    print(Name, MA, start_date, end_date)