i designed an app but the visualization wasn’t displaying when i connected to my call back, please help
import dash
from datetime import datetime, date
import numpy as np
from dash import dcc, html
from dash.dependencies import Output, Input
import plotly.express as px
import dash_bootstrap_components as dbc
import pandas as pd
import pandas_datareader.data as web
import datetime
# importing and cleaning of dataset
# ********************************************************************************
df = pd.read_excel("C:\\Users\\Moritus Peters\\Downloads\\Adidas Sales.xlsx")
df[:3]
# fetching invoice Month column from invoice Date
df['Month'] = pd.to_datetime(df['Invoice Date']).dt.month_name()
# fetching invoice day column from invoice Date
df['Day'] = pd.to_datetime(df['Invoice Date']).dt.day_name()
# fetching invoice year column from invoice Date
df['year'] = pd.to_datetime(df['Invoice Date']).dt.year
df['Revenue'] = df['Price per Unit'] * df['Units Sold']
# Calculate Total Revenue per City
product_revenue = df.groupby('City')['Revenue'].sum().sort_values(ascending=False)
gh = product_revenue.head().reset_index()
# Calculate Total Revenue per City
product_revenue = df.groupby('Product')['Revenue'].sum().sort_values(ascending=False)
PR = product_revenue.head().reset_index()
# Calculate Total Revenue per Month
Month_revenue = df.groupby('Month')['Revenue'].sum().sort_values(ascending=False)
MR = Month_revenue.head().reset_index()
# Calculate Total Sales per Region
Region_sales = df.groupby('Region')['Total Sales'].sum().sort_values(ascending=False)
RS = Region_sales.head().reset_index()
# Calculate Total Revenue per Product
product_TotalSales = df.groupby('Product')['Total Sales'].sum().sort_values(ascending=False)
PS = product_TotalSales.reset_index()
# Calculate Total Revenue per Region
Region_Revenue = df.groupby('Region')['Revenue'].sum().sort_values(ascending=False)
RR = Region_Revenue.head().reset_index()
# *******************************************************************************************
# https://www.bootstrapcdn.com/bootswatch/
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP],
meta_tags=[{'name': 'viewport',
'content': 'width=device-width, initial-scale=1.0'}]
)
# Layout section: Bootstrap (https://hackerthemes.com/bootstrap-cheatsheet/)
# ************************************************************************
app.layout = dbc.Container([
dbc.NavbarSimple(
children=[
dbc.NavItem(dbc.NavLink('Home', href="https://www.adidas.com/us/sale"))
], brand='Adidas Sales Dashboard',
brand_href="https://www.adidas.com/us",
color='Primary',
dark=True,
),
dbc.Row([
dbc.Col([
dbc.Card(
dbc.CardBody([
html.H5("State", className="card-title"),
dcc.Dropdown(
id='id_dropdown',
multi=False,
options=[{'label': x, 'value': x} for x in sorted(df['State'].unique())],
value=sorted(df['State'].unique())[0],
),
html.H5('Sales Method', className='card-title'),
dcc.Checklist(
id='id_checklist',
options=[{'label': i, 'value': i} for i in sorted(df['Sales Method'].unique())],
value=sorted([df['Sales Method'].unique()[0]]),
inline=True
),
]),
),
], width=3),
dbc.Col([
dbc.Card(
dbc.CardBody([
html.H1("ADIDAS SALES DASHBOARD", className='text-center text-primary mb-4'),
dcc.Graph(id='bar-chart1', figure={}),
dcc.Graph(id='bar-chart2', figure={}),
dcc.Graph(id='pie-chart', figure={}),
dcc.Graph(id='funnel-chart', figure={}),
]),
),
], width=9),
]),
])
# ************************************************************************************************************
# Callback to Update Charts, Graphs, and Map based on dropdown and Checklist values
@app.callback(
Output('bar-chart1', 'figure'),
[Input('id_dropdown', 'value'),
Input('id_checklist', 'value')]
)
def update_bar_chart1(City_Revenue, selected_methods):
fig1RC = gh[(gh['City'] == City_Revenue) & (gh['Revenue'].isin(selected_methods))]
figure = px.bar(fig1RC, x='City', y='Revenue', color='City', title='Revenue by City')
return figure
@app.callback(
Output('bar-chart2', 'figure'),
[Input('id_dropdown', 'value'),
Input('id_checklist', 'value')]
)
def update_bar_chart2(Product_Revenue, selected_methods):
fig1RP = PR[(PR['Product'] == Product_Revenue) & (PR['Revenue'].isin(selected_methods))]
figure = px.bar(fig1RP, x='Product', y='Revenue', color='Product', title='Revenue by Product')
return figure
@app.callback(
Output('pie-chart', 'figure'),
[Input('id_dropdown', 'value'),
Input('id_checklist', 'value')]
)
def update_pie_chart(Region_Sales, selected_methods):
figRS = RS[(RS['Region'] == Region_Sales) & (RS['Total Sales'].isin(selected_methods))]
figure = px.pie(
figRS, # Display only the top 10 customers for better visualization
values='Total Sales',
names='Region',
title='Top Region Contribution to Total Sales',
labels={'Total Sales': 'Total Sales', 'Region': 'Region'},
)
return figure
@app.callback(
Output('funnel-chart', 'figure'),
[Input('id_dropdown', 'value'),
Input('id_checklist', 'value')]
)
def update_funnel_chart(Region_Revenue, selected_methods):
figRR = RR[(RR['Region'] == Region_Revenue) & (RR['Revenue'].isin(selected_methods))]
fig = px.funnel(
figRR,
x='Region',
y='Revenue',
color='Region',
hover_name='Region',
animation_frame='Region',
title='Total Revenue per Region',
labels={'Region': 'Region Revenue (%)'},
)
return fig
if __name__ == "__main__":
app.run_server(debug=True, port=8075)