Spaces:
Running
Running
File size: 3,991 Bytes
27ca709 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
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
@app.callback(
[Output("logins-by-country", "figure"),
Output("session-duration-by-gender", "figure"),
Output("data-breaches-by-country", "figure"),
Output("two-fa-usage", "figure"),
Output("filtered-data-table", "children")],
[Input("country-filter", "value"),
Input("gender-filter", "value"),
Input("status-filter", "value")]
)
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(debug=True)
|