├── assets └── dash.png ├── README.md ├── requirements.txt └── main.py /assets/dash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmitrii-khizbullin/dash_dashboard/HEAD/assets/dash.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple dataset visualization with Dash 2 | 3 | [Online demo on AWS](http://3.132.176.163:8050/) 4 | 5 | ![preview](assets/dash.png) 6 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Brotli==1.0.7 2 | certifi==2020.6.20 3 | click==7.1.2 4 | dash==1.14.0 5 | dash-core-components==1.10.2 6 | dash-html-components==1.0.3 7 | dash-renderer==1.6.0 8 | dash-table==4.9.0 9 | Flask==1.1.2 10 | Flask-Compress==1.5.0 11 | future==0.18.2 12 | itsdangerous==1.1.0 13 | Jinja2==2.11.2 14 | MarkupSafe==1.1.1 15 | numpy==1.19.1 16 | pandas==1.1.0 17 | plotly==4.9.0 18 | python-dateutil==2.8.1 19 | pytz==2020.1 20 | retrying==1.3.3 21 | six==1.15.0 22 | Werkzeug==1.0.1 23 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import dash 3 | import dash_core_components as dcc 4 | import dash_html_components as html 5 | from dash.dependencies import Input, Output 6 | import plotly.express as px 7 | import numpy as np 8 | 9 | 10 | class Dashboard: 11 | def __init__(self): 12 | claims_df = pd.read_csv("claims_test.csv") 13 | # print(claims_df) 14 | # print(claims_df.columns) 15 | claims_df["CLAIM_SPECIALTY"] = claims_df["CLAIM_SPECIALTY"].str.lower() 16 | claims_df["CLAIM_SPECIALTY"] = claims_df["CLAIM_SPECIALTY"].apply( 17 | lambda v: v.strip(" \t") if isinstance(v, str) else v) 18 | 19 | # print(claims_df["SERVICE_CATEGORY"].unique()) 20 | # print(len(claims_df["SERVICE_CATEGORY"].unique())) 21 | 22 | # print(claims_df["CLAIM_SPECIALTY"].unique()) 23 | # print(len(claims_df["CLAIM_SPECIALTY"].unique())) 24 | 25 | # print(claims_df["PAYER"].unique()) 26 | # print(len(claims_df["PAYER"].unique())) 27 | 28 | self.service_categories = claims_df["SERVICE_CATEGORY"].unique().tolist() 29 | self.payers = claims_df["PAYER"].unique().tolist() 30 | self.df = claims_df 31 | 32 | self.app = dash.Dash() 33 | 34 | self.category_cl = dcc.Checklist( 35 | id='category_cl', 36 | options=[{"label": c, "value": c} for c in self.service_categories], 37 | value=self.service_categories) 38 | 39 | self.payers_cl = dcc.Checklist( 40 | id='payers_cl', 41 | options=[{"label": p, "value": p} for p in self.payers], 42 | value=self.payers) 43 | 44 | self.months = np.sort(self.df["MONTH"].unique()) 45 | self.index_to_month = {i + 1: str(month) for i, month in enumerate(self.months)} 46 | 47 | self.date_slider = dcc.RangeSlider( 48 | id='month_slider', 49 | updatemode='mouseup', 50 | count=1, 51 | min=1, 52 | max=len(self.months), 53 | step=1, 54 | value=[1, len(self.months)], 55 | marks=self.index_to_month, 56 | pushable=0, 57 | ) 58 | 59 | self.app.layout = html.Div(id="main", children=[ 60 | html.H1(children="My dashboard"), 61 | html.Br(), 62 | self.date_slider, 63 | html.Br(), 64 | html.Br(), 65 | self.category_cl, 66 | html.Br(), 67 | self.payers_cl, 68 | dcc.Graph(id="all_claims_graph"), 69 | dcc.Graph(id="specialty_graph"), 70 | ]) 71 | 72 | self.app.callback( 73 | [ 74 | Output(component_id="specialty_graph", component_property="figure"), 75 | Output(component_id="all_claims_graph", component_property="figure"), 76 | ], 77 | [ 78 | Input(component_id="category_cl", component_property="value"), 79 | Input(component_id="payers_cl", component_property="value"), 80 | Input(component_id="month_slider", component_property="value"), 81 | ], 82 | )(self.render) 83 | 84 | def run(self): 85 | self.app.run_server(debug=False, host='0.0.0.0') 86 | 87 | def render(self, category_cl, payers_cl, month_slider_value): 88 | min_max_month = [self.months[i-1] for i in month_slider_value] 89 | df_range = self.df[(self.df["MONTH"] >= min_max_month[0]) & (self.df["MONTH"] <= min_max_month[1])] 90 | df_cat = df_range[df_range["SERVICE_CATEGORY"].isin(category_cl)] 91 | df_payers = df_cat[df_cat["PAYER"].isin(payers_cl)] 92 | # print(df_payers) 93 | 94 | df_all_claims = df_payers.groupby(["SERVICE_CATEGORY", "PAYER"])["PAID_AMOUNT"].sum().reset_index() 95 | # print(df_all_claims) 96 | color_discrete_map = {sc: color for sc, color in zip(self.service_categories, px.colors.qualitative.G10)} 97 | all_claims_fig = px.bar( 98 | df_all_claims, 99 | x="PAYER", 100 | y="PAID_AMOUNT", 101 | color="SERVICE_CATEGORY", 102 | barmode="group", 103 | color_discrete_map=color_discrete_map) 104 | 105 | df_specialty = df_payers.groupby(["CLAIM_SPECIALTY"])["PAID_AMOUNT"].sum().reset_index() 106 | # print(df_specialty) 107 | df_specialty_top = df_specialty.sort_values("PAID_AMOUNT", ascending=False).head(50) 108 | # print(df_specialty_top) 109 | figure_specialty = px.bar( 110 | df_specialty_top, 111 | x="CLAIM_SPECIALTY", 112 | y="PAID_AMOUNT", 113 | ) 114 | 115 | return figure_specialty, all_claims_fig 116 | 117 | 118 | def main(): 119 | dashboard = Dashboard() 120 | dashboard.run() 121 | 122 | 123 | if __name__ == "__main__": 124 | main() 125 | --------------------------------------------------------------------------------