Spaces:
Sleeping
Sleeping
import dash | |
from dash import dcc, html, Input, Output | |
import pandas as pd | |
import plotly.express as px | |
# Load the data | |
def load_data(): | |
file_path = 'digital_identity_data.xlsx' | |
return pd.read_excel(file_path) | |
data = load_data() | |
# Initialize Dash app | |
app = dash.Dash(__name__) | |
app.title = "Digital Identity Dashboard" | |
# Layout | |
def generate_layout(): | |
return html.Div([ | |
html.H1("Digital Identity Dashboard", style={"textAlign": "center"}), | |
html.Div([ | |
html.Label("Select Countries:"), | |
dcc.Checklist( | |
id="country-filter", | |
options=[{"label": country, "value": country} for country in data["Country"].unique()], | |
value=data["Country"].unique().tolist(), | |
inline=True | |
), | |
html.Label("Select Genders:"), | |
dcc.Checklist( | |
id="gender-filter", | |
options=[{"label": gender, "value": gender} for gender in data["Gender"].unique()], | |
value=data["Gender"].unique().tolist(), | |
inline=True | |
), | |
html.Label("Select Account Status:"), | |
dcc.Checklist( | |
id="status-filter", | |
options=[{"label": status, "value": status} for status in data["Account Status"].unique()], | |
value=data["Account Status"].unique().tolist(), | |
inline=True | |
), | |
], style={"marginBottom": "20px"}), | |
html.Div(id="filtered-data-table"), | |
html.Div([ | |
dcc.Graph(id="logins-by-country"), | |
dcc.Graph(id="session-duration-by-gender") | |
], style={"display": "flex", "flexWrap": "wrap"}), | |
html.Div([ | |
dcc.Graph(id="data-breaches-by-country"), | |
dcc.Graph(id="two-fa-usage") | |
], style={"display": "flex", "flexWrap": "wrap"}) | |
]) | |
app.layout = generate_layout | |
# Callbacks for filtering data and updating graphs | |
def update_dashboard(selected_countries, selected_genders, selected_statuses): | |
# Filter data | |
filtered_data = data[ | |
(data["Country"].isin(selected_countries)) & | |
(data["Gender"].isin(selected_genders)) & | |
(data["Account Status"].isin(selected_statuses)) | |
] | |
# Logins by country | |
logins_by_country = filtered_data.groupby("Country")["Number of Logins"].sum().reset_index() | |
fig1 = px.bar(logins_by_country, x="Country", y="Number of Logins", title="Logins by Country", color="Country") | |
# Session duration by gender | |
session_duration_by_gender = filtered_data.groupby("Gender")["Session Duration (Minutes)"].mean().reset_index() | |
fig2 = px.bar(session_duration_by_gender, x="Gender", y="Session Duration (Minutes)", title="Session Duration by Gender", color="Gender") | |
# Data breaches by country | |
fig3 = px.pie(filtered_data, names="Country", values="Data Breaches Reported", title="Data Breaches by Country") | |
# 2FA usage | |
two_fa_usage = filtered_data["2FA Enabled"].value_counts().reset_index() | |
two_fa_usage.columns = ["2FA Enabled", "Count"] | |
fig4 = px.pie(two_fa_usage, names="2FA Enabled", values="Count", title="2FA Usage") | |
# Filtered data table | |
table_html = html.Div([ | |
html.H3("Filtered Data Table"), | |
dash.dash_table.DataTable( | |
data=filtered_data.to_dict('records'), | |
columns=[{"name": i, "id": i} for i in filtered_data.columns], | |
page_size=10, | |
style_table={"overflowX": "auto"} | |
) | |
]) | |
return fig1, fig2, fig3, fig4, table_html | |
# Run app | |
if __name__ == "__main__": | |
app.run_server(host='0.0.0.0', port=7860, debug=False) |