在回调期间为多个 inputs/states 重命名破折号中的菜单属性

Renaming menu properties in dash for multiple inputs/states during callback

所以我遇到了以下问题: 我有一个应用程序,可以将我的数据作为 csv 文件上传。 我想制作一个应该被分类器列细分的图表。我希望用户能够从选择中选择他想要绘制的图表类型,以及哪一列确实包含分类器。

我创建了一个用于选择图表的 RadioItem 对象和一个用于选择分类器列的下拉菜单,我会将所选图表作为输入传递,将所选分类器作为状态传递。

不,问题是,从 RadioItem 和下拉菜单中选择的项目称为 'value'。所以我会得到这样的东西:

def RadioItems():
    return dcc.RadioItems(
    options=[
        {'label': 'lineplot', 'value': 'lineplot'},
        {'label': 'None', 'value' : 'None'}

    ],
    value='None',
    id='graph_selector')
def classifier_choice(df):
    '''
    called when data is uploaded
    '''
    columns=df.columns
    classifieroptions= [{'label' :k, 'value' :k} for k in columns]
    return dcc.Dropdown(
            #label='Classifier Column',
            id='classifier_choice',
            options=classifieroptions,
            placeholder='select the classifier column')
app.layout = html.Div([

    dcc.Upload(
        id='upload-data',
        children=html.Div([
            'Drag and Drop or ',
            html.A('Select Files')
        ]),
        style={
            'width': '100%',
            'height': '60px',
            'lineHeight': '60px',
            'borderWidth': '1px',
            'borderStyle': 'dashed',
            'borderRadius': '5px',
            'textAlign': 'center',
            'margin': '10px'
        },
        # Allow multiple files to be uploaded
        multiple=True
    ),
    html.Table(id='output-data-upload'),
    RadioItems(),

    dcc.Graph(id='migration_data'),
    #hidden divs for storing data
    html.Div(id='shared_data', style={'display':'none'})
])
graph_options={'None':print(), 'lineplot':GD.lineplot}
@app.callback(Output('migration_data', 'figure'),
              [Input('graph_selector', 'value')],
              [State('classifier_choice', 'value')])


def get_value(value, value):
    return graph_options[value](df, value, testmode=True)

尽管我收到错误: "AttributeError: 'Div' object has no attribute 'keys'"

这当然没有任何意义,因为无法区分这两个值。 有没有办法重命名下拉菜单的 value 属性,或者以以下方式将其值分配给另一个变量:

classifier=classifier_choice.value()

或类似的东西?

回答关于参数名称的问题:回调装饰器获取组件的属性并将它们作为给定顺序的参数传递给函数。您可以随意命名参数。

def get_value(selected_graph, selected_classifier):
    return graph_options[selected_graph](df, selected_classifier, testmode=True)

您可能需要 return 一些与 Graph 组件的图形属性兼容的东西。尽管如此,为了使 graph_options' 的值变为 return 函数对象,您需要去掉 print.

之后的括号