import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]
df = pd.read_csv(‘dash.csv’)
drug = df.groupby([‘drug’]).mean().round(2).reset_index()
dfToList = drug[‘drug’].tolist()
app = dash.Dash(name, external_stylesheets = external_stylesheets)
option_species = dict(zip(dfToList, dfToList))
app.layout = html.Div([
html.Div([
html.Div([
dcc.Dropdown(
id = 'dropdown',
options = [{"label": key, "value": value} for key, value in option_species.items()]),
dcc.Graph(id = 'indicator-graphic'),
])])])
@app.callback(
dash.dependencies.Output(‘indicator-graphic’, ‘figure’),
[dash.dependencies.Input(‘dropdown’, ‘value’)])
def update_graph(dropdown):
a = df.set_index([‘dropdown’])
name = ‘dropdown’
a1 = a.loc[[name]].mean().to_frame().reset_index()
return {
‘data’: [go.Bar(
x = a1[‘index’][:-1],
y = a1[0]
)]
}
In the following code, I am making a bargraph that would update and filter through a database based on a dropdown box.
I am getting the following errors
Callback error updating indicator-graphic.figure
and
KeyError: “None of [‘dropdown’] are in the columns”
Can anyone help me out on this?