MadhuV28 commited on
Commit
6878592
·
1 Parent(s): 89f09c1

Create new file

Browse files
Files changed (1) hide show
  1. app.py +112 -0
app.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time # to simulate a real time data, time loop
2
+
3
+ import numpy as np # np mean, np random
4
+ import pandas as pd # read csv, df manipulation
5
+ import plotly.express as px # interactive charts
6
+ import streamlit as st # 🎈 data web app development
7
+ dataset_url = "https://raw.githubusercontent.com/Lexie88rus/bank-marketing-analysis/master/bank.csv"
8
+
9
+ # read csv from a URL
10
+ @st.experimental_memo
11
+ def get_data() -> pd.DataFrame:
12
+ return pd.read_csv(dataset_url)
13
+
14
+ df = get_data()
15
+ st.set_page_config(
16
+ page_title="Real-Time Data Science Dashboard",
17
+ page_icon="✅",
18
+ layout="wide",
19
+ )
20
+ # dashboard title
21
+ st.title("Real-Time / Live Data Science Dashboard")
22
+ # top-level filters
23
+ job_filter = st.selectbox("Select the Job", pd.unique(df["job"]))
24
+ # dataframe filter
25
+ df = df[df["job"] == job_filter]
26
+ # create three columns
27
+ kpi1, kpi2, kpi3 = st.columns(3)
28
+
29
+ # fill in those three columns with respective metrics or KPIs
30
+ kpi1.metric(
31
+ label="Age ⏳",
32
+ value=round(avg_age),
33
+ delta=round(avg_age) - 10,
34
+ )
35
+
36
+ kpi2.metric(
37
+ label="Married Count 💍",
38
+ value=int(count_married),
39
+ delta=-10 + count_married,
40
+ )
41
+
42
+ kpi3.metric(
43
+ label="A/C Balance $",
44
+ value=f"$ {round(balance,2)} ",
45
+ delta=-round(balance / count_married) * 100,
46
+ )
47
+ # create two columns for charts
48
+ fig_col1, fig_col2 = st.columns(2)
49
+
50
+ with fig_col1:
51
+ st.markdown("### First Chart")
52
+ fig = px.density_heatmap(
53
+ data_frame=df, y="age_new", x="marital"
54
+ )
55
+ st.write(fig)
56
+
57
+ with fig_col2:
58
+ st.markdown("### Second Chart")
59
+ fig2 = px.histogram(data_frame=df, x="age_new")
60
+ st.write(fig2)
61
+ st.markdown("### Detailed Data View")
62
+ st.dataframe(df)
63
+ for seconds in range(200):
64
+
65
+ df["age_new"] = df["age"] * np.random.choice(range(1, 5))
66
+ df["balance_new"] = df["balance"] * np.random.choice(range(1, 5))
67
+ time.sleep(1)
68
+ # creating a single-element container.
69
+ placeholder = st.empty()
70
+ with placeholder.container():
71
+
72
+ # create three columns
73
+ kpi1, kpi2, kpi3 = st.columns(3)
74
+
75
+ # fill in those three columns with respective metrics or KPIs
76
+ kpi1.metric(
77
+ label="Age ⏳",
78
+ value=round(avg_age),
79
+ delta=round(avg_age) - 10,
80
+ )
81
+
82
+ kpi2.metric(
83
+ label="Married Count 💍",
84
+ value=int(count_married),
85
+ delta=-10 + count_married,
86
+ )
87
+
88
+ kpi3.metric(
89
+ label="A/C Balance $",
90
+ value=f"$ {round(balance,2)} ",
91
+ delta=-round(balance / count_married) * 100,
92
+ )
93
+
94
+ # create two columns for charts
95
+ fig_col1, fig_col2 = st.columns(2)
96
+
97
+ with fig_col1:
98
+ st.markdown("### First Chart")
99
+ fig = px.density_heatmap(
100
+ data_frame=df, y="age_new", x="marital"
101
+ )
102
+ st.write(fig)
103
+
104
+ with fig_col2:
105
+ st.markdown("### Second Chart")
106
+ fig2 = px.histogram(data_frame=df, x="age_new")
107
+ st.write(fig2)
108
+
109
+ st.markdown("### Detailed Data View")
110
+ st.dataframe(df)
111
+ time.sleep(1)
112
+