Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import dash
|
2 |
+
from dash import dcc, html, Input, Output
|
3 |
+
import pandas as pd
|
4 |
+
import plotly.express as px
|
5 |
+
|
6 |
+
# Load the data
|
7 |
+
def load_data():
|
8 |
+
file_path = 'digital_identity_data.xlsx'
|
9 |
+
return pd.read_excel(file_path)
|
10 |
+
|
11 |
+
data = load_data()
|
12 |
+
|
13 |
+
# Initialize Dash app
|
14 |
+
app = dash.Dash(__name__)
|
15 |
+
app.title = "Digital Identity Dashboard"
|
16 |
+
|
17 |
+
# Layout
|
18 |
+
def generate_layout():
|
19 |
+
return html.Div([
|
20 |
+
html.H1("Digital Identity Dashboard", style={"textAlign": "center"}),
|
21 |
+
|
22 |
+
html.Div([
|
23 |
+
html.Label("Select Countries:"),
|
24 |
+
dcc.Checklist(
|
25 |
+
id="country-filter",
|
26 |
+
options=[{"label": country, "value": country} for country in data["Country"].unique()],
|
27 |
+
value=data["Country"].unique().tolist(),
|
28 |
+
inline=True
|
29 |
+
),
|
30 |
+
|
31 |
+
html.Label("Select Genders:"),
|
32 |
+
dcc.Checklist(
|
33 |
+
id="gender-filter",
|
34 |
+
options=[{"label": gender, "value": gender} for gender in data["Gender"].unique()],
|
35 |
+
value=data["Gender"].unique().tolist(),
|
36 |
+
inline=True
|
37 |
+
),
|
38 |
+
|
39 |
+
html.Label("Select Account Status:"),
|
40 |
+
dcc.Checklist(
|
41 |
+
id="status-filter",
|
42 |
+
options=[{"label": status, "value": status} for status in data["Account Status"].unique()],
|
43 |
+
value=data["Account Status"].unique().tolist(),
|
44 |
+
inline=True
|
45 |
+
),
|
46 |
+
], style={"marginBottom": "20px"}),
|
47 |
+
|
48 |
+
html.Div(id="filtered-data-table"),
|
49 |
+
|
50 |
+
html.Div([
|
51 |
+
dcc.Graph(id="logins-by-country"),
|
52 |
+
dcc.Graph(id="session-duration-by-gender")
|
53 |
+
], style={"display": "flex", "flexWrap": "wrap"}),
|
54 |
+
|
55 |
+
html.Div([
|
56 |
+
dcc.Graph(id="data-breaches-by-country"),
|
57 |
+
dcc.Graph(id="two-fa-usage")
|
58 |
+
], style={"display": "flex", "flexWrap": "wrap"})
|
59 |
+
])
|
60 |
+
|
61 |
+
app.layout = generate_layout
|
62 |
+
|
63 |
+
# Callbacks for filtering data and updating graphs
|
64 |
+
@app.callback(
|
65 |
+
[Output("logins-by-country", "figure"),
|
66 |
+
Output("session-duration-by-gender", "figure"),
|
67 |
+
Output("data-breaches-by-country", "figure"),
|
68 |
+
Output("two-fa-usage", "figure"),
|
69 |
+
Output("filtered-data-table", "children")],
|
70 |
+
[Input("country-filter", "value"),
|
71 |
+
Input("gender-filter", "value"),
|
72 |
+
Input("status-filter", "value")]
|
73 |
+
)
|
74 |
+
def update_dashboard(selected_countries, selected_genders, selected_statuses):
|
75 |
+
# Filter data
|
76 |
+
filtered_data = data[
|
77 |
+
(data["Country"].isin(selected_countries)) &
|
78 |
+
(data["Gender"].isin(selected_genders)) &
|
79 |
+
(data["Account Status"].isin(selected_statuses))
|
80 |
+
]
|
81 |
+
|
82 |
+
# Logins by country
|
83 |
+
logins_by_country = filtered_data.groupby("Country")["Number of Logins"].sum().reset_index()
|
84 |
+
fig1 = px.bar(logins_by_country, x="Country", y="Number of Logins", title="Logins by Country", color="Country")
|
85 |
+
|
86 |
+
# Session duration by gender
|
87 |
+
session_duration_by_gender = filtered_data.groupby("Gender")["Session Duration (Minutes)"].mean().reset_index()
|
88 |
+
fig2 = px.bar(session_duration_by_gender, x="Gender", y="Session Duration (Minutes)", title="Session Duration by Gender", color="Gender")
|
89 |
+
|
90 |
+
# Data breaches by country
|
91 |
+
fig3 = px.pie(filtered_data, names="Country", values="Data Breaches Reported", title="Data Breaches by Country")
|
92 |
+
|
93 |
+
# 2FA usage
|
94 |
+
two_fa_usage = filtered_data["2FA Enabled"].value_counts().reset_index()
|
95 |
+
two_fa_usage.columns = ["2FA Enabled", "Count"]
|
96 |
+
fig4 = px.pie(two_fa_usage, names="2FA Enabled", values="Count", title="2FA Usage")
|
97 |
+
|
98 |
+
# Filtered data table
|
99 |
+
table_html = html.Div([
|
100 |
+
html.H3("Filtered Data Table"),
|
101 |
+
dash.dash_table.DataTable(
|
102 |
+
data=filtered_data.to_dict('records'),
|
103 |
+
columns=[{"name": i, "id": i} for i in filtered_data.columns],
|
104 |
+
page_size=10,
|
105 |
+
style_table={"overflowX": "auto"}
|
106 |
+
)
|
107 |
+
])
|
108 |
+
|
109 |
+
return fig1, fig2, fig3, fig4, table_html
|
110 |
+
|
111 |
+
# Run app
|
112 |
+
if __name__ == "__main__":
|
113 |
+
app.run_server(debug=True)
|