11import logging
2+
3+ import dash_bootstrap_components as dbc
24import plotly .express as px
35from dash import dash_table , dcc , html
46from dash .dependencies import Input , Output
57from django_plotly_dash import DjangoDash
6- import dash_bootstrap_components as dbc
7- from datetime import datetime
88
99from .functions import clean_livelihood_data , clean_wealth_group_data
1010
1515logger = logging .getLogger (__name__ )
1616
1717# Dash app
18- app = DjangoDash (
19- "Inventory_dashboard" ,
20- suppress_callback_exceptions = True ,
21- external_stylesheets = [dbc .themes .BOOTSTRAP ]
22- )
18+ app = DjangoDash ("Inventory_dashboard" , suppress_callback_exceptions = True , external_stylesheets = [dbc .themes .BOOTSTRAP ])
2319app .title = "HEA Dashboard"
2420
2521# Layout
3430 id = "country-dropdown" ,
3531 options = [{"label" : country , "value" : country } for country in unique_countries ],
3632 placeholder = "Select Country(s)" ,
37- multi = True ,
33+ multi = True ,
3834 ),
3935 ],
4036 style = {"flex" : "1" , "marginRight" : "10px" }, # Set flex and spacing
4844 multi = True ,
4945 ),
5046 ],
51- style = {"flex" : "1" },
47+ style = {"flex" : "1" },
5248 ),
5349 ],
5450 style = {
55- "display" : "flex" ,
51+ "display" : "flex" ,
5652 "width" : "100%" ,
57- "justifyContent" : "space-between" ,
58- "marginBottom" : "20px" ,
53+ "justifyContent" : "space-between" ,
54+ "marginBottom" : "20px" ,
5955 },
6056 ),
6157 html .Div (
@@ -123,24 +119,37 @@ def update_charts(selected_countries, selected_zones):
123119
124120 # Filter data based on selected livelihood zones
125121 if selected_zones :
126- filtered_livelihood = filtered_livelihood [filtered_livelihood ["livelihood_zone_baseline_label" ].isin (selected_zones )]
122+ filtered_livelihood = filtered_livelihood [
123+ filtered_livelihood ["livelihood_zone_baseline_label" ].isin (selected_zones )
124+ ]
127125 filtered_wealth = filtered_wealth [filtered_wealth ["livelihood_zone_baseline_label" ].isin (selected_zones )]
128126
129127 # Group data for charts
130128 livelihood_grouped = (
131- filtered_livelihood .groupby (["livelihood_zone_baseline_label" , "strategy_type_label" ]).size ().reset_index (name = "Count" )
129+ filtered_livelihood .groupby (["livelihood_zone_baseline_label" , "strategy_type_label" ])
130+ .size ()
131+ .reset_index (name = "Count" )
132+ )
133+ wealth_grouped = (
134+ filtered_wealth .groupby ("livelihood_zone_baseline_label" )
135+ .size ()
136+ .reset_index (name = "Wealth Characteristics Count" )
132137 )
133- wealth_grouped = filtered_wealth .groupby ("livelihood_zone_baseline_label" ).size ().reset_index (name = "Wealth Characteristics Count" )
134138 wealth_monthly_grouped = (
135- filtered_wealth .groupby (["created_month" , "livelihood_zone_baseline_label" ]).size ().reset_index (name = "Wealth Characteristics Count" )
139+ filtered_wealth .groupby (["created_month" , "livelihood_zone_baseline_label" ])
140+ .size ()
141+ .reset_index (name = "Wealth Characteristics Count" )
136142 )
137143
138144 wealth_fig = px .bar (
139145 wealth_grouped ,
140146 x = "livelihood_zone_baseline_label" ,
141147 y = "Wealth Characteristics Count" ,
142148 title = "Wealth Characteristics per Baseline" ,
143- labels = {"livelihood_zone_baseline_label" : "Baseline" , "Wealth Characteristics Count" : "No. of Wealth Characteristics" },
149+ labels = {
150+ "livelihood_zone_baseline_label" : "Baseline" ,
151+ "Wealth Characteristics Count" : "No. of Wealth Characteristics" ,
152+ },
144153 )
145154
146155 livelihood_fig = px .bar (
@@ -149,7 +158,11 @@ def update_charts(selected_countries, selected_zones):
149158 y = "Count" ,
150159 color = "livelihood_zone_baseline_label" ,
151160 title = "Livelihood Strategies per Baseline" ,
152- labels = {"strategy_type_label" : "Strategy Type" , "Count" : "No. of Livelihood Strategies" , "livelihood_zone_baseline_label" : "Baseline" },
161+ labels = {
162+ "strategy_type_label" : "Strategy Type" ,
163+ "Count" : "No. of Livelihood Strategies" ,
164+ "livelihood_zone_baseline_label" : "Baseline" ,
165+ },
153166 )
154167
155168 # Stacked/multiple column chart for wealth characteristics by month
@@ -169,6 +182,7 @@ def update_charts(selected_countries, selected_zones):
169182
170183 return zone_options , wealth_fig , livelihood_fig , wealth_monthly_fig , livelihood_grouped .to_dict ("records" )
171184
185+
172186# Run the app
173187if __name__ == "__main__" :
174188 app .run_server (debug = True )
0 commit comments