✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚾️ It's finally Baseball season! Root for the home team... & Register for our Sports Analytics Webinar!

Callback function not using the source file to update the graph

Im using a csv file as my data source. I want the graph to update based on the radio button selection i make, please my source code below.

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

df = pd.read_csv(‘population2.csv’)
fst_yvalues = df[‘PopEstimate2010’]/1000000
scd_yvalues = df[‘PopEstimate2011’]/1000000
trd_yvalues = df[‘PopEstimate2012’]/1000000

app = dash.Dash()
app.layout = html.Div(children=[
html.H1(‘My first Interactive Graph’),
html.Div(dcc.RadioItems(id=‘radio_items’,
options=[{‘label’:‘PopEstimate2010’,‘value’:‘pop2010’},
{‘label’:‘PopEstimate2011’,‘value’: ‘pop2011’},
{‘label’:‘PopEstimate2011’ ,‘value’:‘pop2012’}],
value=‘pop2010’)),
html.Br(),
html.Div(children=[
dcc.Graph(id=‘int_bar’)
])
])

@app.callback(Output(‘int_bar’,‘figure’),
[Input(‘radio_items’,‘value’)])
def make_bar_chart(value):
trace = []
if value == ‘pop2010’:
trarce = [go.Bar(x=df[‘Name’],y=fst_yvalues, name=‘Pop2010’)]
elif value == ‘pop2011’:
trarce = [go.Bar(x=df[‘Name’],y=scd_yvalues)]
else:
trarce = [go.Bar(x=df[‘Name’],y=trd_yvalues)]

layout = go.Layout(title='MY FIRST GRAPH',
                    xaxis=dict(title='MY X-AXIS'),
                    yaxis=dict(title='MY Y-AXIS'),hovermode='closest')

figure = go.Figure(data=trace,layout=layout)
return figure

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