Jun Xiong
commited on
Commit
·
428ae5c
1
Parent(s):
fba0a98
data
Browse files- Dashboard_Sample.png +0 -0
- README.md +3 -1
- app.py +24 -122
- board.csv +12 -0
- pyproject.toml +15 -0
- requirements.txt +2 -4
- supermarkt_sales.xlsx +0 -0
Dashboard_Sample.png
DELETED
Binary file (24.8 kB)
|
|
README.md
CHANGED
@@ -8,4 +8,6 @@ app_file: app.py
|
|
8 |
pinned: false
|
9 |
---
|
10 |
|
11 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
8 |
pinned: false
|
9 |
---
|
10 |
|
11 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
12 |
+
|
13 |
+
poetry run streamlit run app.py
|
app.py
CHANGED
@@ -1,130 +1,32 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
# @YouTube: https://youtube.com/c/CodingIsFun
|
4 |
-
# @Project: Sales Dashboard w/ Streamlit
|
5 |
|
6 |
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
import streamlit as st # pip install streamlit
|
11 |
|
12 |
-
|
13 |
-
st.set_page_config(page_title="Sales Dashboard", page_icon=":bar_chart:", layout="wide")
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
def get_data_from_excel():
|
18 |
-
df = pd.read_excel(
|
19 |
-
io="supermarkt_sales.xlsx",
|
20 |
-
engine="openpyxl",
|
21 |
-
sheet_name="Sales",
|
22 |
-
skiprows=3,
|
23 |
-
usecols="B:R",
|
24 |
-
nrows=1000,
|
25 |
-
)
|
26 |
-
# Add 'hour' column to dataframe
|
27 |
-
df["hour"] = pd.to_datetime(df["Time"], format="%H:%M:%S").dt.hour
|
28 |
-
return df
|
29 |
|
30 |
-
|
|
|
31 |
|
32 |
-
#
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
options=df["Customer_type"].unique(),
|
43 |
-
default=df["Customer_type"].unique(),
|
44 |
-
)
|
45 |
-
|
46 |
-
gender = st.sidebar.multiselect(
|
47 |
-
"Select the Gender:",
|
48 |
-
options=df["Gender"].unique(),
|
49 |
-
default=df["Gender"].unique()
|
50 |
-
)
|
51 |
-
|
52 |
-
df_selection = df.query(
|
53 |
-
"City == @city & Customer_type ==@customer_type & Gender == @gender"
|
54 |
-
)
|
55 |
-
|
56 |
-
# Check if the dataframe is empty:
|
57 |
-
if df_selection.empty:
|
58 |
-
st.warning("No data available based on the current filter settings!")
|
59 |
-
st.stop() # This will halt the app from further execution.
|
60 |
-
|
61 |
-
# ---- MAINPAGE ----
|
62 |
-
st.title(":bar_chart: Sales Dashboard")
|
63 |
-
st.markdown("##")
|
64 |
-
|
65 |
-
# TOP KPI's
|
66 |
-
total_sales = int(df_selection["Total"].sum())
|
67 |
-
average_rating = round(df_selection["Rating"].mean(), 1)
|
68 |
-
star_rating = ":star:" * int(round(average_rating, 0))
|
69 |
-
average_sale_by_transaction = round(df_selection["Total"].mean(), 2)
|
70 |
-
|
71 |
-
left_column, middle_column, right_column = st.columns(3)
|
72 |
-
with left_column:
|
73 |
-
st.subheader("Total Sales:")
|
74 |
-
st.subheader(f"US $ {total_sales:,}")
|
75 |
-
with middle_column:
|
76 |
-
st.subheader("Average Rating:")
|
77 |
-
st.subheader(f"{average_rating} {star_rating}")
|
78 |
-
with right_column:
|
79 |
-
st.subheader("Average Sales Per Transaction:")
|
80 |
-
st.subheader(f"US $ {average_sale_by_transaction}")
|
81 |
-
|
82 |
-
st.markdown("""---""")
|
83 |
-
|
84 |
-
# SALES BY PRODUCT LINE [BAR CHART]
|
85 |
-
sales_by_product_line = df_selection.groupby(by=["Product line"])[["Total"]].sum().sort_values(by="Total")
|
86 |
-
fig_product_sales = px.bar(
|
87 |
-
sales_by_product_line,
|
88 |
-
x="Total",
|
89 |
-
y=sales_by_product_line.index,
|
90 |
-
orientation="h",
|
91 |
-
title="<b>Sales by Product Line</b>",
|
92 |
-
color_discrete_sequence=["#0083B8"] * len(sales_by_product_line),
|
93 |
-
template="plotly_white",
|
94 |
-
)
|
95 |
-
fig_product_sales.update_layout(
|
96 |
-
plot_bgcolor="rgba(0,0,0,0)",
|
97 |
-
xaxis=(dict(showgrid=False))
|
98 |
-
)
|
99 |
-
|
100 |
-
# SALES BY HOUR [BAR CHART]
|
101 |
-
sales_by_hour = df_selection.groupby(by=["hour"])[["Total"]].sum()
|
102 |
-
fig_hourly_sales = px.bar(
|
103 |
-
sales_by_hour,
|
104 |
-
x=sales_by_hour.index,
|
105 |
-
y="Total",
|
106 |
-
title="<b>Sales by hour</b>",
|
107 |
-
color_discrete_sequence=["#0083B8"] * len(sales_by_hour),
|
108 |
-
template="plotly_white",
|
109 |
-
)
|
110 |
-
fig_hourly_sales.update_layout(
|
111 |
-
xaxis=dict(tickmode="linear"),
|
112 |
-
plot_bgcolor="rgba(0,0,0,0)",
|
113 |
-
yaxis=(dict(showgrid=False)),
|
114 |
-
)
|
115 |
-
|
116 |
-
|
117 |
-
left_column, right_column = st.columns(2)
|
118 |
-
left_column.plotly_chart(fig_hourly_sales, use_container_width=True)
|
119 |
-
right_column.plotly_chart(fig_product_sales, use_container_width=True)
|
120 |
-
|
121 |
-
|
122 |
-
# ---- HIDE STREAMLIT STYLE ----
|
123 |
-
hide_st_style = """
|
124 |
-
<style>
|
125 |
-
#MainMenu {visibility: hidden;}
|
126 |
-
footer {visibility: hidden;}
|
127 |
-
header {visibility: hidden;}
|
128 |
-
</style>
|
129 |
-
"""
|
130 |
-
st.markdown(hide_st_style, unsafe_allow_html=True)
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
|
|
|
|
3 |
|
4 |
|
5 |
+
# Function to highlight the given value
|
6 |
+
def highlight_value(val, highlight):
|
7 |
+
color = 'yellow' if val == highlight else ''
|
8 |
+
return f'background-color: {color}'
|
9 |
|
10 |
+
# Value to be highlighted
|
11 |
+
highlight = "ongoing"
|
|
|
12 |
|
13 |
+
df = pd.read_csv('board.csv')
|
|
|
14 |
|
15 |
+
# Apply the highlighting
|
16 |
+
df_styled = df.style.applymap(lambda x: highlight_value(x, highlight))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
# Convert the styled DataFrame to HTML
|
19 |
+
df_html = df_styled.set_table_attributes('class="dataframe"')
|
20 |
|
21 |
+
# Add CSS for setting cell width
|
22 |
+
css = """
|
23 |
+
<style>
|
24 |
+
.dataframe td {
|
25 |
+
max-width: 100px;
|
26 |
+
word-wrap: break-word;
|
27 |
+
}
|
28 |
+
</style>
|
29 |
+
"""
|
30 |
|
31 |
+
# Display the styled DataFrame with custom CSS in Streamlit
|
32 |
+
st.write(df_html, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
board.csv
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
City,parcel,street,building,buildablelot,due,tsec,status
|
2 |
+
San Jose, 247614, 41241,324217,0,0,2010432,ongoing
|
3 |
+
San Francisco, 0, 0,0,0,0,0,tostart
|
4 |
+
Los Angeles, 0, 0,0,0,0,0,tostart
|
5 |
+
San Diego, 0, 0,0,0,0,0,tostart
|
6 |
+
Sacramento, 0, 0,0,0,0,0,tostart
|
7 |
+
Fresno, 0, 0,0,0,0,0,tostart
|
8 |
+
Oakland, 0, 0,0,0,0,0,tostart
|
9 |
+
Long Beach, 0, 0,0,0,0,0,tostart
|
10 |
+
Anaheim, 0, 0,0,0,0,0,tostart
|
11 |
+
Bakersfield, 0, 0,0,0,0,0,tostart
|
12 |
+
Riverside, 0, 0,0,0,0,0,tostart
|
pyproject.toml
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tool.poetry]
|
2 |
+
name = "dashboard"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = ""
|
5 |
+
authors = ["Jun Xiong"]
|
6 |
+
readme = "README.md"
|
7 |
+
|
8 |
+
[tool.poetry.dependencies]
|
9 |
+
python = "^3.12"
|
10 |
+
pandas = "^2.2.2"
|
11 |
+
streamlit = "^1.36.0"
|
12 |
+
|
13 |
+
[build-system]
|
14 |
+
requires = ["poetry-core"]
|
15 |
+
build-backend = "poetry.core.masonry.api"
|
requirements.txt
CHANGED
@@ -1,4 +1,2 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
plotly==5.13.1
|
4 |
-
streamlit==1.25.0
|
|
|
1 |
+
pandas==1.1.3
|
2 |
+
streamlit==0.72.0
|
|
|
|
supermarkt_sales.xlsx
DELETED
Binary file (125 kB)
|
|