✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Drop down not working

Hi Team,

I have written the below code where in when ever i select a particular drop down i want t graph to be displayed the dropdown is appering but the grap is not coming

Code:
import pandas as pd
import matplotlib.pyplot as plt
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.express as px #(need to pip install plotly==4.4.1)
%matplotlib inline
df = pd.read_csv(r"C:\Users\Adnan\Desktop\MAR2020.csv")
app = dash.Dash(name)

#---------------------------------------------------------------
app.layout = html.Div([
html.Div([
html.Label([‘ANALYSIS MARCH’]),
dcc.Dropdown(
id=‘my_dropdown’,
options=[
{‘label’: ‘March2020’, ‘value’: ‘Count’},
],
value=‘March2020’,
multi=False,
clearable=False,
style={“width”: “50%”}
),
]),

html.Div([
    dcc.Graph(id='the_graph')
]),

])

#---------------------------------------------------------------
@app.callback(
Output(component_id=‘the_graph’, component_property=‘figure’),
[Input(component_id=‘my_dropdown’, component_property=‘value’)]
)

def update_graph(my_dropdown):
dff = df

px.histogram(df, x="Trantype", y='Count')

return (histogram)

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

Hi @Adnan

A good way to start debugging your code is to use something from the tutorial that is proven to work - like https://plotly.com/python/histograms/

Try using this in your callback:

df = px.data.tips()
fig = px.histogram(df, x="total_bill") 
return fig

Does this histogram show up? If yes, then you know the problem is your code in the callback. I expect you get an error message like histogram is not defined. Now go back to using your data and syntax like in the example. If you want to name the figure “histogram” - try:

histogram = px.histogram(df, x="Trantype", y='Count')
return histogram

If that doesn’t work, it’s probably your data. You can try print(df) to take a look at the data in your callback

Good luck!