jeonghin commited on
Commit
dfe2e39
1 Parent(s): ecc4bbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -46
app.py CHANGED
@@ -10,62 +10,64 @@ subgroup_select1 = pn.widgets.Select(name='Layers', options=["conv2d5", "conv2d6
10
  subgroup_select2 = pn.widgets.Select(name='Layers', options=["conv2d5", "conv2d6", "conv2d7", "conv2d8", "conv2d9", "linear1", "linear2"])
11
 
12
  # Bind the widgets to the create_plot function
13
- @pn.depends(subgroup_select.param.value)
14
- def create_plot(layers):
15
- 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)
16
- color_dict = {
17
- "ClassifierA_Cr203_C6": "#B3262A",
18
- "ClassifierA_test_stim": "#2f559a",
19
- "ClassifierA_test_unstim": "#5AADC5",
20
- }
21
-
22
- # Define a selection for zooming and panning (interval)
23
- zoom = alt.selection_interval(bind='scales')
24
-
25
- # Define a selection for the legend
26
- legend_selection = alt.selection_multi(fields=['class_label'], bind='legend')
27
-
28
-
29
- # Create the Altair chart object
30
- chart = alt.Chart(df_train_umap).mark_circle(size=4, opacity=1).encode(
31
- x=alt.X("UMAP_1:Q", scale=alt.Scale(zero=False)),
32
- y=alt.Y("UMAP_2:Q", scale=alt.Scale(zero=False)),
33
- color=alt.Color("class_label:N", scale=alt.Scale(domain=list(color_dict.keys()), range=list(color_dict.values()))),
34
- tooltip=['UMAP_1', 'UMAP_2', 'class_label'],
35
- opacity=alt.condition(legend_selection, alt.value(1), alt.value(0)) # Use the selection here to control opacity
36
- ).properties(
37
- title=f"UMAP Test Data Labels - {layers}",
38
- ).add_selection(
39
- legend_selection, # Add the selection to the chart
40
 
41
- zoom
42
- ).configure_axis(
43
- grid=False
44
- ).configure_view(
45
- strokeWidth=0
46
- )
47
-
48
- return chart
49
-
50
- # # Combine everything in a Panel Column to create an app
51
- # app = pn.Column("# UMAP Data Interactive Visualization", subgroup_select, pn.panel(create_plot, reactive=True))
52
-
53
- # # Set the app to be servable
54
- # app.servable()
55
-
56
- # Create two instances of the main layout
57
- # Main layout 1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  main_layout1 = pn.Column(
59
  "# Data Interactive Visualization (SPARCS)",
60
  subgroup_select1,
61
- pn.panel(create_plot, reactive=True),
62
  )
63
 
64
  # Main layout 2
65
  main_layout2 = pn.Column(
66
  "# Data Interactive Visualization (SPARCS)",
67
  subgroup_select2,
68
- pn.panel(create_plot, reactive=True),
69
  )
70
 
71
  # Place layouts side by side using pn.Row
 
10
  subgroup_select2 = pn.widgets.Select(name='Layers', options=["conv2d5", "conv2d6", "conv2d7", "conv2d8", "conv2d9", "linear1", "linear2"])
11
 
12
  # Bind the widgets to the create_plot function
13
+ def create_plot(subgroup_select):
14
+ @pn.depends(subgroup_select.param.value)
15
+ def _plot(layers):
16
+ 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)
17
+ color_dict = {
18
+ "ClassifierA_Cr203_C6": "#B3262A",
19
+ "ClassifierA_test_stim": "#2f559a",
20
+ "ClassifierA_test_unstim": "#5AADC5",
21
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ # Define a selection for zooming and panning (interval)
24
+ zoom = alt.selection_interval(bind='scales')
25
+
26
+ # Define a selection for the legend
27
+ legend_selection = alt.selection_multi(fields=['class_label'], bind='legend')
28
+
29
+
30
+ # Create the Altair chart object
31
+ chart = alt.Chart(df_train_umap).mark_circle(size=4, opacity=1).encode(
32
+ x=alt.X("UMAP_1:Q", scale=alt.Scale(zero=False)),
33
+ y=alt.Y("UMAP_2:Q", scale=alt.Scale(zero=False)),
34
+ color=alt.Color("class_label:N", scale=alt.Scale(domain=list(color_dict.keys()), range=list(color_dict.values()))),
35
+ tooltip=['UMAP_1', 'UMAP_2', 'class_label'],
36
+ opacity=alt.condition(legend_selection, alt.value(1), alt.value(0)) # Use the selection here to control opacity
37
+ ).properties(
38
+ title=f"UMAP Test Data Labels - {layers}",
39
+ ).add_selection(
40
+ legend_selection, # Add the selection to the chart
41
+
42
+ zoom
43
+ ).configure_axis(
44
+ grid=False
45
+ ).configure_view(
46
+ strokeWidth=0
47
+ )
48
+
49
+ return chart
50
+ return _plot
51
+
52
+ # # Combine everything in a Panel Column to create an app
53
+ # app = pn.Column("# UMAP Data Interactive Visualization", subgroup_select, pn.panel(create_plot, reactive=True))
54
+
55
+ # # Set the app to be servable
56
+ # app.servable()
57
+
58
+ # Create two instances of the main layout
59
+ # Main layout 1
60
  main_layout1 = pn.Column(
61
  "# Data Interactive Visualization (SPARCS)",
62
  subgroup_select1,
63
+ pn.panel(create_plot(subgroup_select1), reactive=True),
64
  )
65
 
66
  # Main layout 2
67
  main_layout2 = pn.Column(
68
  "# Data Interactive Visualization (SPARCS)",
69
  subgroup_select2,
70
+ pn.panel(create_plot(subgroup_select2), reactive=True),
71
  )
72
 
73
  # Place layouts side by side using pn.Row