Line Chart with callbacks and dropdown list

I want to show every column on the line chart while using a drop-down list of variables but doesn't work.
how to solve this?

features = df.columns.drop(‘Year’)
app.layout =html.Div([
dcc.Dropdown(id=‘features-picker’,options=[{‘label’:i, ‘value’:i} for i in features]
,value=‘GDP Real, National currency\n(Billion EGP)’),
dcc.Graph(id=‘graph’)

    ],style={'width': '48%', 'float': 'right', 'display': 'inline-block'})

@app.callback(Output(‘graph’, ‘figure’),[Input(‘features-picker’,‘value’)])

def update(Selected_feature):
filtered_df=df[[‘Year’,Selected_feature]]

fig=px.line(filtered_df,x="Year",y='Selected_feature')
return fig

if name == ‘main’:
app.run_server(debug=False)

Hello @Moaaz,

Welcome to the community!

It is a little hard to determine what you are actually trying to do here.

Your function should return px.line(filtered_df, x='Year', y=Selected_feature)

If you want multiple columns, change your drop down to allow multi. :slight_smile:

2 Likes