Introduction

Demonstrating widget two-way communication.

In [1]:
import ipywidgets as widgets
from clustergrammer2 import Network, CGM2, net
import json
import pandas as pd
df = {}
>> clustergrammer2 backend version 0.17.1

Make DataFrame

In [2]:
df['clean'] = pd.read_csv('rc_two_cat_clean.csv', index_col=0)
df['meta_col'] = pd.read_csv('meta_col.csv', index_col=0)
df['clean'].shape
Out[2]:
(38, 29)
In [3]:
df['meta_cat_col'] = pd.DataFrame()
df['meta_cat_col'].loc['Cat', 'color'] = 'red'
df['meta_cat_col'].loc['Dog', 'color'] = 'yellow'
df['meta_cat_col'].loc['Shark', 'color'] = 'black'
df['meta_cat_col'].loc['Snake', 'color'] = 'blue'
df['meta_cat_col'].loc['Lizard', 'color'] = 'green'
df['meta_cat_col']
Out[3]:
color
Cat red
Dog yellow
Shark black
Snake blue
Lizard green
In [4]:
df['meta_cat_col'].to_csv('meta_cat_col.csv')
In [5]:
df['meta_col']['Values'] = pd.Series(1.1, index=df['meta_col'].index.tolist())
df['meta_col'].loc['H1781', 'Values'] = -2
df['meta_col'].loc['H838', 'Values'] = 3
In [6]:
viz_cats = ['Category', 'Gender', 'Values']
In [7]:
n1 = Network(CGM2)
n1.set_global_cat_colors(df['meta_cat_col'])
n1.load_df(df['clean'], meta_col=df['meta_col'], col_cats=viz_cats)
n1.set_manual_category(col='Category', preferred_cats=df['meta_cat_col'])
n1.widget()
In [8]:
n2 = Network(CGM2)
n2.load_df(df['clean'], meta_col=df['meta_col'], col_cats=viz_cats)
n2.set_global_cat_colors(df['meta_cat_col'])
n2.set_manual_category(col='Category', preferred_cats=df['meta_cat_col'])
n2.widget(link_net=n1)
In [ ]: