I have a dataset and I want to plot some graphs. I created a plotly graph that loads correctly with a callback function where I can select the year I want the data. The dataset loads correctly and there are no missings or errors. But Whenever I try to change the data nothing happens.
my dataset has columns like this codass Q NF CURS 240011 1 7 2010 240011 2 5 2010 240012 1 2 2011
I tried starting with a blank graph, and nothing happens. The data is fine cause the initial graph loads correctly it’s on the updating procedure.
import pandas as pd
import numpy as np
import dash
import dash_core_components as dcc
from dash.dependencies import Input, Output
import dash_html_components as html
import plotly.graph_objs as go
FaseIni = pd.read_csv('/Users/Jordi/Documents/Universitat/TFG/tfg/Spyder path/qfaseini18.csv',sep=';',encoding='utf-8')
Q=[1,2]
anys=FaseIni['CURS'].unique()
pv = FaseIni.pivot_table( index=['CODASS'], columns=['Q'], values=['NF'], fill_value=0)
trace1=go.Bar(x=pv.index, y =pv[('NF',1)],name='q1')
trace2=go.Bar(x=pv.index, y =pv[('NF',2)],name='q2')
app = dash.Dash()
app.layout = html.Div([
html.Div([
dcc.Dropdown(
id='Anys',
options= [{'label':'2010' , 'value':2010 },{'label':'2011' , 'value':2011 }],
value =2010,
)
]),
html.Div([
dcc.Graph(
id='notes',
figure={
'data':[trace1,trace2]
}
)
])
])
@app.callback(
Output('notes','figure'),
[Input('Anys','value')])
def update_graph(Anys):
pv2 = FaseIni.loc[FaseIni['CURS'] == Anys]
pv2 = pv2.pivot_table( index=['CODASS'], columns=['Q'], values=['NF'],
fill_value=0)
trace3=go.Bar(x=pv2.index, y =pv2[('Anys',1)],name='q1')
trace4=go.Bar(x=pv2.index, y =pv2[('Anys',2)],name='q2')
return {'data':[trace3,trace4]}
The initial graph loads correctly, it just doesn’t update