I’m sorry if this is the wrong place to post this question but I’ve been trying to solve this for hours with no luck and could really use some help. I have a data set that I’m trying to create a bar chart for using plotly dash. The bar charts x-axis remains the same but I’d like to change the y-axis based on a selection from a drop-down menu. Here is my current code:
app.layout = html.Div(children=[
dcc.Dropdown(id = ‘drop_down’, options=[
{‘label’: ‘Total Prisoner Count’, ‘value’: ‘TPC’},
{‘label’: ‘Total Violent Crimes’, ‘value’: ‘TVC’},
{‘label’: ‘Total Murder Crimes’, ‘value’: ‘TMC’},
{‘label’: ‘Total Robbery Crimes’, ‘value’: ‘TROC’},
{‘label’: ‘Total Assault Crimes’, ‘value’: ‘TAC’},
], value = ‘TPC’) ,
dcc.Graph(id = ‘bar_chart’),
])
@app.callback(
dash.dependencies.Output(‘bar_chart’, ‘figure’),
[dash.dependencies.Input(‘drop_down’, ‘value’)]
)
def updateBar(selected_yaxis):
if selected_yaxis == ‘TPC’:
df = mod_data_2016[mod_data_2016[‘selected_yaxis’] == selected]
fig = px.bar(x=mod_data_2016[‘jurisdiction’], y = mod_data_2016[‘prisoner_count’])
print(‘here’)
else:
fig = px.bar(x=mod_data_2016[‘jurisdiction’], y = mod_data_2016[‘state_population’])
print()
return fig
if name == ‘main’:
app.run_server(debug=False)
I’m currently just trying to get one selection to work since the others don’t really matter if I can’t even get one.
The current code does not produce anything. I know I’m missing code, however when trying to look at plotly examples, I am unable to figure out what I need. Any help would be really appreciated