Graph not updating as per dropdown value Here is my code

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input,Output
import plotly.graph_objs as go
import pandas as pd

app=dash.Dash()
df=pd.read_csv(“kpi.csv”)

name_option=list()
for name in df[‘Name’]:
name_option.append({‘label’:str(name),‘value’:name})

app.layout=html.Div([
html.Div([dcc.Graph(id=‘graph’)]),
html.Div([dcc.Dropdown(id=‘name_picker’,options=name_option,placeholder=‘Select a Name’)])

])
#@app.callback(Output(‘graph’,‘figure’),[Input(‘name_picker’,‘value’)])
@app.callback(
dash.dependencies.Output(‘graph’, ‘figure’),
[dash.dependencies.Input( ‘name_picker’,‘value’)])

def update_figure(selected_name):
filtered_name=df[df[‘Name’]==selected_name]
traces=[]

labels=["Communication Skills","Problem Solving","Team Work","Learning Agility","Motivated","Reliabilty","Resilience","Emotional Intelligence","Integrity"]
#values=df.iloc[(df['Name']==selected_name).index[0],1:].tolist()
values=df.iloc[(df['Name']==selected_name).index[0],1:].tolist()
traces.append(go.Pie(
        labels=labels,
        values=values
        ))
return{'data':traces,'layout':go.Layout(title='KPI pie')}

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

//
csv file
Name,Communication Skills,Problem Solving,Team Work,Learning Agility,Motivated,Reliabilty,Resilience,Emotional Intelligence,Integrity
A,4,4,3,2,4,3,3,4,2
B,4,3,5,3,2,1,3,4,4
C,3,4,5,3,3,4,4,3,3
D,4,4,4,5,4,3,4,3,5
E,4,3,3,3,4,4,5,4,4
F,5,5,5,5,3,2,1,3,2
G,4,4,3,5,3,2,3,4,1
H,4,4,3,2,1,4,4,3,2
F,4,3,3,5,1,2,2,3,2

I am attaching image that shows graph isnt updating. can anyone help please?

Shouldn’t that be
def update_figure(name_picker):
Because that contains your input variable.

1 Like

Hello Grunherz,
I updated the code. still the graph isnt updating

Still not quite getting dataframes, but this should work:
Add the following, as there is initial no value in name_picker you get an error. I solve this the dirty way by adding a try catch block (probably not the best way, but alas):

try:
    dfb = df[df['Name']==name_picker].index.values.astype(int)[0]
except:
    dfb=0

and change

to
values=df.iloc[(df[‘Name’]==name_picker).index[dfb],:].tolist()

You kept selecting the first row, no matter what choice you make. So, the index has to move with the selection.

1 Like

Thanks alot :clap::clap: It worked.

i just altered one more thing.I didnt want name as a value in my list of values so i did

values=df.iloc[(df[‘Name’]==name_picker).index[dfb],1:].tolist()