├── Main.py ├── README.md ├── UI.py ├── __pycache__ └── UI.cpython-311.pyc ├── data.xlsx ├── pages └── 🌎 Add Record.py ├── requirements.txt └── style.css /Main.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import pandas as pd 3 | import streamlit.components.v1 as stc 4 | import plotly.express as px 5 | import time 6 | from streamlit_option_menu import option_menu 7 | from numerize.numerize import numerize 8 | import plotly.express as px 9 | import plotly.subplots as sp 10 | import plotly.graph_objects as go 11 | 12 | #page behaviour 13 | st.set_page_config(page_title="Descriptive Analytics ", page_icon="🌎", layout="wide") 14 | 15 | #remove default theme 16 | theme_plotly = None # None or streamlit 17 | 18 | 19 | # CSS Style 20 | with open('style.css')as f: 21 | st.markdown(f"", unsafe_allow_html = True) 22 | 23 | #load excel file 24 | df=pd.read_excel('data.xlsx', sheet_name='Sheet1') 25 | 26 | 27 | #2. switcher 28 | st.sidebar.header("Please Filter Here:") 29 | region= st.sidebar.multiselect( 30 | "Select the Region:", 31 | options=df["Region"].unique(), 32 | default=df["Region"].unique() 33 | ) 34 | location = st.sidebar.multiselect( 35 | "Select the Location:", 36 | options=df["Location"].unique(), 37 | default=df["Location"].unique(), 38 | ) 39 | construction = st.sidebar.multiselect( 40 | "Select the Construction:", 41 | options=df["Construction"].unique(), 42 | default=df["Construction"].unique() 43 | 44 | 45 | ) 46 | df_selection = df.query( 47 | "Region == @region & Location ==@location & Construction == @construction" 48 | ) 49 | 50 | #method/function 51 | 52 | def HomePage(): 53 | #1. print dataframe 54 | with st.expander("🧭 My database"): 55 | #st.dataframe(df_selection,use_container_width=True) 56 | shwdata = st.multiselect('Filter :', df_selection.columns, default=[]) 57 | st.dataframe(df_selection[shwdata],use_container_width=True) 58 | 59 | #2. compute top Analytics 60 | 61 | total_investment = float(df_selection['Investment'].sum()) 62 | investment_mode = float(df_selection['Investment'].mode()) 63 | investment_mean = float(df_selection['Investment'].mean()) 64 | investment_median= float(df_selection['Investment'].median()) 65 | rating = float(df_selection['Rating'].sum()) 66 | 67 | #3. columns 68 | total1,total2,total3,total4,total5 = st.columns(5,gap='large') 69 | with total1: 70 | 71 | st.info('Total Investment', icon="🔍") 72 | st.metric(label = 'sum TZS', value= f"{total_investment:,.0f}") 73 | 74 | with total2: 75 | st.info('Most frequently', icon="🔍") 76 | st.metric(label='Mode TZS', value=f"{investment_mode:,.0f}") 77 | 78 | with total3: 79 | st.info('Investment Average', icon="🔍") 80 | st.metric(label= 'Mean TZS',value=f"{investment_mean:,.0f}") 81 | 82 | with total4: 83 | st.info('Investment Marging', icon="🔍") 84 | st.metric(label='Median TZS',value=f"{investment_median:,.0f}") 85 | 86 | with total5: 87 | st.info('Ratings', icon="🔍") 88 | st.metric(label='Rating',value=numerize(rating),help=f"""Total rating: {rating}""") 89 | 90 | st.markdown("""---""") 91 | 92 | #graphs 93 | 94 | def Graphs(): 95 | total_investments = int(df_selection["Investment"].sum()) 96 | average_rating = round(df_selection["Rating"].mean(), 1) 97 | star_rating = ":star:" * int(round(average_rating, 0)) 98 | average_investment = round(df_selection["Investment"].mean(), 2) 99 | 100 | #1. simple bar graph 101 | investment_by_businessType = ( 102 | df_selection.groupby(by=["BusinessType"]).count()[["Investment"]].sort_values(by="Investment") 103 | ) 104 | fig_investment = px.bar( 105 | investment_by_businessType, 106 | x="Investment", 107 | y=investment_by_businessType.index, 108 | orientation="h", 109 | title="Investment by Business Type", 110 | color_discrete_sequence=["#0083B8"] * len(investment_by_businessType), 111 | template="plotly_white", 112 | ) 113 | 114 | fig_investment.update_layout( 115 | plot_bgcolor="rgba(0,0,0,0)", 116 | xaxis=(dict(showgrid=False)) 117 | ) 118 | 119 | #2. simple line graph------------------ 120 | investment_by_state = df_selection.groupby(by=["State"]).count()[["Investment"]] 121 | fig_state = px.line( 122 | investment_by_state, 123 | x=investment_by_state.index, 124 | orientation="v", 125 | y="Investment", 126 | title="Investment by Region ", 127 | color_discrete_sequence=["#0083B8"] * len(investment_by_state), 128 | template="plotly_white", 129 | ) 130 | fig_state.update_layout( 131 | xaxis=dict(tickmode="linear"), 132 | plot_bgcolor="rgba(0,0,0,0)", 133 | yaxis=(dict(showgrid=False)), 134 | ) 135 | 136 | left_column, right_column,center = st.columns(3) 137 | left_column.plotly_chart(fig_state, use_container_width=True) 138 | right_column.plotly_chart(fig_investment, use_container_width=True) 139 | 140 | #pie chart 141 | with center: 142 | fig = px.pie(df_selection, values='Rating', names='State', title='Regions by Ratings') 143 | fig.update_layout(legend_title="Regions", legend_y=0.9) 144 | fig.update_traces(textinfo='percent+label', textposition='inside') 145 | st.plotly_chart(fig, use_container_width=True, theme=theme_plotly) 146 | 147 | #-----PROGRESS BAR----- 148 | 149 | def ProgressBar(): 150 | st.markdown("""""",unsafe_allow_html=True,) 151 | target=3000000000 152 | current=df_selection['Investment'].sum() 153 | percent=round((current/target*100)) 154 | my_bar = st.progress(0) 155 | 156 | if percent>100: 157 | st.subheader("Target 100 complited") 158 | else: 159 | st.write("you have ", percent, " % " ," of ", (format(target, ',d')), " TZS") 160 | for percent_complete in range(percent): 161 | time.sleep(0.1) 162 | my_bar.progress(percent_complete + 1,text="Target percentage") 163 | 164 | #-----SIDE BAR----- 165 | 166 | def sideBar(): 167 | with st.sidebar: 168 | selected=option_menu( 169 | menu_title="Menu", 170 | #menu_title=None, 171 | options=["Home","Progress"], 172 | icons=["house","eye"], 173 | menu_icon="cast", #option 174 | default_index=0, #option 175 | ) 176 | if selected=="Home": 177 | try: 178 | HomePage() 179 | Graphs() 180 | except: 181 | st.warning("one or more options are mandatory ! ") 182 | 183 | 184 | if selected=="Progress": 185 | try: 186 | ProgressBar() 187 | Graphs() 188 | except: 189 | st.warning("one or more options are mandatory ! ") 190 | 191 | #print side bar 192 | sideBar() 193 | 194 | footer=""" 214 | 217 | """ 218 | st.markdown(footer,unsafe_allow_html=True) 219 | 220 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Untitled 10](https://github.com/shamiraty/AnalyticsDashboard-with-Excel-file/assets/129072179/6bbda7d9-9539-4daa-a1b3-85287abe8190) 2 | ![Untitled 12](https://github.com/shamiraty/AnalyticsDashboard-with-Excel-file/assets/129072179/1b4a3b89-17bd-4238-bf7c-155324a4c737) 3 | ![Untitled 13](https://github.com/shamiraty/AnalyticsDashboard-with-Excel-file/assets/129072179/8b8bf6f4-f9c8-4ac1-9180-da60bde0e854) 4 | ![Untitled 15](https://github.com/shamiraty/AnalyticsDashboard-with-Excel-file/assets/129072179/71f07ae3-eb20-4481-9483-7a3266ced364) 5 | ![Untitled 16](https://github.com/shamiraty/AnalyticsDashboard-with-Excel-file/assets/129072179/b36d4dba-a41a-49f7-9a85-e3045baf6aee) 6 | ![Untitled 18](https://github.com/shamiraty/AnalyticsDashboard-with-Excel-file/assets/129072179/0223ce79-6398-4285-bc5e-9aa6ae8b9fa5) 7 | ![Untitled 20](https://github.com/shamiraty/AnalyticsDashboard-with-Excel-file/assets/129072179/f381cf1e-fa25-4b21-b060-b4a51c8cab86) 8 | ![2](https://github.com/shamiraty/AnalyticsDashboard-with-Excel-file/assets/129072179/f2590286-051e-4384-97d5-966499311cd6) 9 | ![1](https://github.com/shamiraty/AnalyticsDashboard-with-Excel-file/assets/129072179/251cdd77-46df-45f8-9417-a7ae8e9f6264) 10 | ![3](https://github.com/shamiraty/AnalyticsDashboard-with-Excel-file/assets/129072179/82b47d47-ac59-4640-a33b-425826254032) 11 | ![4](https://github.com/shamiraty/AnalyticsDashboard-with-Excel-file/assets/129072179/29faedca-be29-4c65-8e85-2de48315542c) 12 | ![6](https://github.com/shamiraty/AnalyticsDashboard-with-Excel-file/assets/129072179/c3c05845-9d39-4ec0-a978-3ad70be19968) 13 | ![5](https://github.com/shamiraty/AnalyticsDashboard-with-Excel-file/assets/129072179/a7cfa34c-c15d-4ac5-89cd-2d34901386f1) 14 | 15 | -------------------------------------------------------------------------------- /UI.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | def heading(): 3 | st.markdown(""" 4 | 5 | 6 |
7 |
8 | 9 | 10 | ⚛ Analytics Dashboard | Python & Streamlit 11 |
12 |
13 | 14 | 15 | """, unsafe_allow_html=True) 16 | 17 | -------------------------------------------------------------------------------- /__pycache__/UI.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shamiraty/AnalyticsDashboard-with-Excel-file/325a0ecbef19d090aa8d8f21626420c35225997b/__pycache__/UI.cpython-311.pyc -------------------------------------------------------------------------------- /data.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shamiraty/AnalyticsDashboard-with-Excel-file/325a0ecbef19d090aa8d8f21626420c35225997b/data.xlsx -------------------------------------------------------------------------------- /pages/🌎 Add Record.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import pandas as pd 3 | import seaborn as sns 4 | from UI import * 5 | 6 | st.set_page_config(page_title="Descriptive Analytics ", page_icon="📈", layout="wide") 7 | heading() 8 | 9 | if 'number_of_rows' not in st.session_state: 10 | st.session_state['number_of_rows']=3 11 | st.session_state['type']='Categorical' 12 | 13 | 14 | increment=st.sidebar.button('show more columns ➕') 15 | if increment: 16 | st.session_state.number_of_rows +=1 17 | decrement=st.sidebar.button('show fewer columns ➖') 18 | if decrement: 19 | st.session_state.number_of_rows -=1 20 | 21 | df=pd.read_excel('data.xlsx', sheet_name='Sheet1') 22 | 23 | 24 | 25 | 26 | theme_plotly = None # None or streamlit 27 | 28 | # Style 29 | with open('style.css')as f: 30 | st.markdown(f"", unsafe_allow_html = True) 31 | 32 | 33 | st.markdown("##") 34 | 35 | st.sidebar.header("Add New Product") 36 | options_form=st.sidebar.form("Option Form") 37 | location=options_form.selectbox("Location",{"Urban","Rural"}) 38 | state=options_form.selectbox("State",{"Dodoma","Kilimanjaro","Dar es Salaam","Kigoma","Iringa","Mwanza"}) 39 | region=options_form.selectbox("Region",{"East","Midwest","Northeast","Central"}) 40 | investment=options_form.number_input("Investment") 41 | construction=options_form.selectbox("Construction",{"Frame","Metal Clad","Fire Resist","Masonry"}) 42 | businesstype=options_form.selectbox("Business Type",{"Manufacturing","Apartment","Office Bldg","Farming","Construction","Recreation","Hospitality","Organization","Retail","Other"}) 43 | earthquake=options_form.selectbox("Earthquake",{"Yes","No"}) 44 | flood=options_form.selectbox("Flood",{"Yes","No"}) 45 | rating=options_form.number_input("Rating") 46 | add_data=options_form.form_submit_button(label="Add new record") 47 | 48 | if add_data: 49 | if investment !="" or location !="": 50 | df = pd.concat([df, pd.DataFrame.from_records([{ 51 | 'Location': location, 52 | 'State':state, 53 | 'Region':region, 54 | 'Investment':int(investment), 55 | 'Construction':construction, 56 | 'BusinessType':businesstype, 57 | 'Earthquake':earthquake, 58 | 'Flood':flood, 59 | 'Rating':float(rating) 60 | }])]) 61 | try: 62 | df.to_excel("data.xlsx",index=False) 63 | except: 64 | st.warning("Close dataset") 65 | st.success("New record has been added successfully !") 66 | else: 67 | st.sidebar.error("product name required") 68 | 69 | 70 | 71 | #st.dataframe(df_selection,use_container_width=True) 72 | shwdata = st.multiselect('Filter :', df.columns, default=["Location","State","Region","Investment","Construction","BusinessType","Earthquake"]) 73 | st.dataframe(df.tail(st.session_state['number_of_rows']),use_container_width=True,) 74 | 75 | 76 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Markdown==3.4.3 2 | markdown-it-py==2.2.0 3 | MarkupSafe==2.1.2 4 | matplotlib==3.7.1 5 | numerize==0.12 6 | numpy==1.23.5 7 | oauthlib==3.2.2 8 | openpyxl==3.1.2 9 | opt-einsum==3.3.0 10 | packaging==23.1 11 | pandas==2.0.1 12 | pandas-profiling==3.2.0 13 | streamlit==1.22.0 14 | streamlit-apexjs==0.0.3 15 | streamlit-card==0.0.4 16 | streamlit-elements==0.1.0 17 | streamlit-option-menu==0.3.2 18 | streamlit-pandas-profiling==0.1.3 19 | plotly==5.14.1 20 | plotly-express==0.4.1 21 | scikit-learn==1.2.2 22 | seaborn==0.12.2 23 | pandas-profiling==3.2.0 24 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | [data-testid=metric-container] { 2 | box-shadow: 0 0 4px #cccccc; 3 | padding: 10px; 4 | } 5 | 6 | .plot-container>div { 7 | box-shadow: 0 0 4px #cccccc; 8 | padding: 10px; 9 | 10 | 11 | } 12 | 13 | div[data-testid="stExpander"] div[role="button"] p 14 | { 15 | font-size: 1.3rem; 16 | color:rgb(235, 238, 238); 17 | } --------------------------------------------------------------------------------