So I have the following problem:
I have an app where I can upload my data as a csv file.
I want to make a graph which should be subdivided by a classifier column. I want the user to be able to pick what kind of graph he wants to plot from a selection and also which column does contain the classifier.
I have created a RadioItem object for picking the graph and a dropdown menu for selecting the classifier column and I would pass the chosen graph as the input and the chosen classifier as a state.
No the problem is, that the selected item from both, the RadioItem as well as the dropdown menu is called ‘value’. So I would get something like this:
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)
Despite me getting the error:
“AttributeError: ‘Div’ object has no attribute ‘keys’”
this of course does not make any sense, since there is no way to differentiate between the two values.
Is there a way to rename the value attribute of a dropdown menu, or assign it’s value to another variable in a way of:
classifier=classifier_choice.value()
or something like that?