Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬 Register for the Oct 27 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

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.Label([‘ANALYSIS MARCH’]),
{‘label’: ‘March2020’, ‘value’: ‘Count’},
style={“width”: “50%”}



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’:

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!