File size: 3,033 Bytes
24bcceb
7ca3184
24bcceb
 
 
 
ecc4bbb
 
 
 
24bcceb
 
dfe2e39
 
 
1fa0829
dfe2e39
 
 
 
 
24bcceb
dfe2e39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f08651d
24bcceb
ecc4bbb
dfe2e39
24bcceb
24475e3
f08651d
 
 
ecc4bbb
dfe2e39
f08651d
 
 
 
 
24bcceb
 
f08651d
24475e3
24bcceb
f08651d
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
import altair as alt
import pandas as pd
import panel as pn

pn.extension('vega')

# Selection widgets 1
subgroup_select1 = pn.widgets.Select(name='Layers', options=["conv2d5", "conv2d6", "conv2d7", "conv2d8", "conv2d9", "linear1", "linear2"])
# Selection widgets 2
subgroup_select2 = pn.widgets.Select(name='Layers', options=["conv2d5", "conv2d6", "conv2d7", "conv2d8", "conv2d9", "linear1", "linear2"])

# Bind the widgets to the create_plot function
def create_plot(subgroup_select):
    @pn.depends(subgroup_select.param.value)
    def _plot(layers):
        df_train_umap = pd.read_csv(f"https://raw.githubusercontent.com/jeonghin/si649_project2/main/data/classifier_1_Test_Data/UMAP_data/Raw_data_UMAP_{layers}.csv").sample(n=5000, random_state=19)
        color_dict = {
            "ClassifierA_Cr203_C6": "#B3262A",
            "ClassifierA_test_stim": "#2f559a",
            "ClassifierA_test_unstim": "#5AADC5",
        }
    
        # Define a selection for zooming and panning (interval)
        zoom = alt.selection_interval(bind='scales')
    
        # Define a selection for the legend
        legend_selection = alt.selection_multi(fields=['class_label'], bind='legend')
    
    
        # Create the Altair chart object
        chart = alt.Chart(df_train_umap).mark_circle(size=4, opacity=1).encode(
            x=alt.X("UMAP_1:Q", scale=alt.Scale(zero=False)),
            y=alt.Y("UMAP_2:Q", scale=alt.Scale(zero=False)),
            color=alt.Color("class_label:N", scale=alt.Scale(domain=list(color_dict.keys()), range=list(color_dict.values()))),
            tooltip=['UMAP_1', 'UMAP_2', 'class_label'],
            opacity=alt.condition(legend_selection, alt.value(1), alt.value(0))  # Use the selection here to control opacity
        ).properties(
            title=f"UMAP Test Data Labels - {layers}",
        ).add_selection(
            legend_selection,  # Add the selection to the chart
        
            zoom
        ).configure_axis(
            grid=False
        ).configure_view(
            strokeWidth=0
        )
    
        return chart
    return _plot
    
    # # Combine everything in a Panel Column to create an app
    # app = pn.Column("# UMAP Data Interactive Visualization", subgroup_select, pn.panel(create_plot, reactive=True))
    
    # # Set the app to be servable
    # app.servable()
    
    # Create two instances of the main layout
    # Main layout 1
main_layout1 = pn.Column(
    "# Data Interactive Visualization (SPARCS)",
    subgroup_select1,
    pn.panel(create_plot(subgroup_select1), reactive=True),
)

# Main layout 2
main_layout2 = pn.Column(
    "# Data Interactive Visualization (SPARCS)",
    subgroup_select2,
    pn.panel(create_plot(subgroup_select2), reactive=True),
)

# Place layouts side by side using pn.Row
side_by_side_layout = pn.Row(main_layout1, main_layout2)

# Create a basic template
template = pn.template.BootstrapTemplate(title='SI649 Project 2')
template.main.append(side_by_side_layout)

# Serve the application
template.servable()