Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,110 +1,66 @@
|
|
1 |
-
import
|
2 |
-
from dash import dcc, html
|
3 |
-
from dash.dependencies import Input, Output
|
4 |
-
import plotly.express as px
|
5 |
import pandas as pd
|
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 |
-
dcc.Dropdown(
|
50 |
-
id="layer-dropdown",
|
51 |
-
options=[{"label": layer, "value": layer} for layer in layers],
|
52 |
-
value=layers[0],
|
53 |
-
),
|
54 |
-
dcc.Graph(id="umap-plot"),
|
55 |
-
]
|
56 |
-
)
|
57 |
-
|
58 |
-
|
59 |
-
# Callback to update the plot based on dropdown selection
|
60 |
-
@app.callback(Output("umap-plot", "figure"), [Input("layer-dropdown", "value")])
|
61 |
-
def update_plot(selected_layer):
|
62 |
-
|
63 |
-
input_path = (
|
64 |
-
f"data/classifier_1_Test_Data/UMAP_data/Raw_data_UMAP_{selected_layer}.csv"
|
65 |
)
|
66 |
-
df_train_umap = pd.read_csv(input_path)
|
67 |
|
68 |
-
|
69 |
-
df_train_umap.sample(frac=1, random_state=19),
|
70 |
-
x="UMAP_1",
|
71 |
-
y="UMAP_2",
|
72 |
-
color="class_label",
|
73 |
-
color_discrete_map=color_dict,
|
74 |
-
title=f"UMAP Test Data Labels - {selected_layer}",
|
75 |
-
)
|
76 |
-
fig.update_traces(
|
77 |
-
marker=dict(size=4, opacity=1, line=dict(width=0)),
|
78 |
-
selector=dict(mode="markers"),
|
79 |
-
)
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
xaxis=dict(
|
84 |
-
scaleanchor="y",
|
85 |
-
scaleratio=1,
|
86 |
-
dtick=2,
|
87 |
-
),
|
88 |
-
yaxis=dict(
|
89 |
-
scaleanchor="x",
|
90 |
-
scaleratio=1,
|
91 |
-
dtick=2,
|
92 |
-
),
|
93 |
-
legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1),
|
94 |
-
)
|
95 |
|
96 |
-
|
97 |
-
|
98 |
-
umap_max = max(df_train_umap["UMAP_1"].max(), df_train_umap["UMAP_2"].max())
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
return fig
|
107 |
|
|
|
|
|
|
|
108 |
|
109 |
-
|
110 |
-
|
|
|
1 |
+
import altair as alt
|
|
|
|
|
|
|
2 |
import pandas as pd
|
3 |
+
import panel as pn
|
4 |
+
|
5 |
+
pn.extension('vega')
|
6 |
+
|
7 |
+
# Selection widgets
|
8 |
+
subgroup_select = pn.widgets.Select(name='Layers', options=["conv2d5", "conv2d6", "conv2d7", "conv2d8", "conv2d9", "linear1", "linear2"])
|
9 |
+
|
10 |
+
# Bind the widgets to the create_plot function
|
11 |
+
@pn.depends(subgroup_select.param.value)
|
12 |
+
def create_plot(layers):
|
13 |
+
df_train_umap = pd.read_csv(f"https://raw.githubusercontent.com/jeonghin/si649_project2_sparcs/main/data/classifier_1_Test_Data/UMAP_data/Raw_data_UMAP_{layers}.csv").sample(n=5000, random_state=19)
|
14 |
+
color_dict = {
|
15 |
+
"ClassifierA_Cr203_C6": "#B3262A",
|
16 |
+
"ClassifierA_test_stim": "#2f559a",
|
17 |
+
"ClassifierA_test_unstim": "#5AADC5",
|
18 |
+
}
|
19 |
+
|
20 |
+
# Define a selection for zooming and panning (interval)
|
21 |
+
zoom = alt.selection_interval(bind='scales')
|
22 |
+
|
23 |
+
# Define a selection for the legend
|
24 |
+
legend_selection = alt.selection_multi(fields=['class_label'], bind='legend')
|
25 |
+
|
26 |
+
|
27 |
+
# Create the Altair chart object
|
28 |
+
chart = alt.Chart(df_train_umap).mark_circle(size=4, opacity=1).encode(
|
29 |
+
x=alt.X("UMAP_1:Q", scale=alt.Scale(zero=False)),
|
30 |
+
y=alt.Y("UMAP_2:Q", scale=alt.Scale(zero=False)),
|
31 |
+
color=alt.Color("class_label:N", scale=alt.Scale(domain=list(color_dict.keys()), range=list(color_dict.values()))),
|
32 |
+
tooltip=['UMAP_1', 'UMAP_2', 'class_label'],
|
33 |
+
opacity=alt.condition(legend_selection, alt.value(1), alt.value(0)) # Use the selection here to control opacity
|
34 |
+
).properties(
|
35 |
+
title=f"UMAP Test Data Labels - {layers}",
|
36 |
+
).add_selection(
|
37 |
+
legend_selection, # Add the selection to the chart
|
38 |
+
|
39 |
+
zoom
|
40 |
+
).configure_axis(
|
41 |
+
grid=False
|
42 |
+
).configure_view(
|
43 |
+
strokeWidth=0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
)
|
|
|
45 |
|
46 |
+
return chart
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
+
# Combine everything in a Panel Column to create an app
|
49 |
+
app = pn.Column("# UMAP Data Interactive Visualization", subgroup_select, pn.panel(create_plot, reactive=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
+
# Set the app to be servable
|
52 |
+
app.servable()
|
|
|
53 |
|
54 |
+
# Main layout
|
55 |
+
main_layout = pn.Column(
|
56 |
+
"# Data Interactive Visualization (SPARCS)",
|
57 |
+
pn.panel(create_plot, reactive=True),
|
58 |
+
subgroup_select,
|
59 |
+
)
|
|
|
60 |
|
61 |
+
# Create a basic template
|
62 |
+
template = pn.template.BootstrapTemplate(title='SI649 Project 2')
|
63 |
+
template.main.append(main_layout)
|
64 |
|
65 |
+
# Serve the application
|
66 |
+
template.servable()
|