-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfisher_dash_app.py
142 lines (132 loc) · 6.08 KB
/
fisher_dash_app.py
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import plotly.graph_objects as go
import pandas as pd
# Initialize Dash app
app = dash.Dash(__name__)
app.title = "Fisher Statistical Analysis Visualization"
# Data for visualization
fisher_data = pd.DataFrame({
"Group": ["White", "Black", "Asian", "Hispanic", "Other"],
"IQ": [100, 108, 105, 102, 98],
"Moral Character": [95, 85, 90, 80, 85],
"Violent Crime": [30, 35, 25, 40, 45],
"Income": [75, 45, 70, 50, 55],
"Reproduction Rate": [48, 55, 47, 60, 52]
})
# App layout
app.layout = html.Div(style={"font-family": "Avenir", "padding": "10px", "max-width": "1000px", "margin": "0 auto", "font-size": "0.95em"}, children=[
# Clickable variable titles for toggling visibility
html.Div(
style={"display": "flex", "justify-content": "center", "gap": "8px", "margin-bottom": "10px"},
children=[
html.Div("IQ", id="toggle-iq", style={"color": "#636EFA", "font-weight": "bold", "cursor": "pointer"}),
html.Div("Moral Character", id="toggle-moral", style={"color": "#EF553B", "font-weight": "bold", "cursor": "pointer"}),
html.Div("Violent Crime", id="toggle-crime", style={"color": "#00CC96", "font-weight": "bold", "cursor": "pointer"}),
html.Div("Income", id="toggle-income", style={"color": "#AB63FA", "font-weight": "bold", "cursor": "pointer"}),
html.Div("Reproduction Rate", id="toggle-reproduction", style={"color": "#FFA15A", "font-weight": "bold", "cursor": "pointer"})
]
),
# Bar Chart
dcc.Graph(id="fisher-chart", style={"width": "100%", "height": "400px", "border": "none"}),
# Sliders with corresponding value display
html.Div(
style={"display": "flex", "justify-content": "space-around", "align-items": "center", "margin-top": "10px"},
children=[
html.Div([
html.Label("IQ", style={"font-weight": "bold", "font-size": "0.85em", "text-align": "center"}),
dcc.Slider(
id="weight-iq",
min=0,
max=5,
step=0.1,
value=1,
marks={i: str(round(i, 1)) for i in range(6)}
),
html.Div(id="weight-iq-value", style={"text-align": "center", "font-size": "0.85em", "margin-top": "-10px"})
], style={"width": "18%"}),
html.Div([
html.Label("Moral Character", style={"font-weight": "bold", "font-size": "0.85em", "text-align": "center"}),
dcc.Slider(
id="weight-moral",
min=0,
max=5,
step=0.1,
value=1,
marks={i: str(round(i, 1)) for i in range(6)}
),
html.Div(id="weight-moral-value", style={"text-align": "center", "font-size": "0.85em", "margin-top": "-10px"})
], style={"width": "18%"}),
html.Div([
html.Label("Violent Crime", style={"font-weight": "bold", "font-size": "0.85em", "text-align": "center"}),
dcc.Slider(
id="weight-crime",
min=0,
max=5,
step=0.1,
value=1,
marks={i: str(round(i, 1)) for i in range(6)}
),
html.Div(id="weight-crime-value", style={"text-align": "center", "font-size": "0.85em", "margin-top": "-10px"})
], style={"width": "18%"}),
html.Div([
html.Label("Income", style={"font-weight": "bold", "font-size": "0.85em", "text-align": "center"}),
dcc.Slider(
id="weight-income",
min=0,
max=5,
step=0.1,
value=1,
marks={i: str(round(i, 1)) for i in range(6)}
),
html.Div(id="weight-income-value", style={"text-align": "center", "font-size": "0.85em", "margin-top": "-10px"})
], style={"width": "18%"}),
html.Div([
html.Label("Reproduction Rate", style={"font-weight": "bold", "font-size": "0.85em", "text-align": "center"}),
dcc.Slider(
id="weight-reproduction",
min=0,
max=5,
step=0.1,
value=1,
marks={i: str(round(i, 1)) for i in range(6)}
),
html.Div(id="weight-reproduction-value", style={"text-align": "center", "font-size": "0.85em", "margin-top": "-10px"})
], style={"width": "18%"})
]
)
])
# Callback to update chart and toggle visibility
@app.callback(
Output("fisher-chart", "figure"),
[Input("weight-iq", "value"),
Input("weight-moral", "value"),
Input("weight-crime", "value"),
Input("weight-income", "value"),
Input("weight-reproduction", "value")]
)
def update_fisher_chart(weight_iq, weight_moral, weight_crime, weight_income, weight_reproduction):
weighted_data = fisher_data.copy()
weighted_data["IQ"] *= weight_iq
weighted_data["Moral Character"] *= weight_moral
weighted_data["Violent Crime"] *= weight_crime
weighted_data["Income"] *= weight_income
weighted_data["Reproduction Rate"] *= weight_reproduction
fig = go.Figure()
for col, color in zip(
["IQ", "Moral Character", "Violent Crime", "Income", "Reproduction Rate"],
["#636EFA", "#EF553B", "#00CC96", "#AB63FA", "#FFA15A"]
):
fig.add_trace(go.Bar(x=weighted_data["Group"], y=weighted_data[col], name=col, marker=dict(color=color), opacity=0.75))
fig.update_layout(
barmode="group",
plot_bgcolor="white",
font=dict(family="Avenir"),
xaxis=dict(showgrid=False, showline=True, zeroline=False, title="Group"),
yaxis=dict(showgrid=True, title="Weighted Value"),
margin=dict(l=10, r=10, t=20, b=10)
)
return fig
if __name__ == "__main__":
app.run_server(debug=True, host="0.0.0.0", port=8080)