Introduction

In [1]:
from ipywidgets import interact
from upsetjs_jupyter_widget import UpSetWidget
import pandas as pd
In [2]:
w = UpSetWidget[str]()
# w.theme = 'dark'
w.mode = 'hover'
In [3]:
w.from_dict(dict(one = ['a', 'b', 'c', 'e', 'g', 'h', 'k', 'l', 'm'], two = ['a', 'b', 'd', 'e', 'j'], three = ['a', 'e', 'f', 'g', 'h', 'i', 'j', 'l', 'm']))
w
Out[3]:
In [4]:
df = pd.DataFrame(dict(
    one=[1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1], 
    two=[1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0], 
    three=[1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1]
), index=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'])
w.from_dataframe(df)
w
Out[4]:
In [5]:
w.sets
Out[5]:
[UpSetSet(name=one, elems={'m', 'h', 'c', 'e', 'k', 'a', 'g', 'l', 'b'}),
 UpSetSet(name=three, elems={'f', 'h', 'm', 'e', 'i', 'j', 'a', 'g', 'l'}),
 UpSetSet(name=two, elems={'a', 'e', 'j', 'd', 'b'})]
In [6]:
w.combinations
Out[6]:
[UpSetSetIntersection(name=one, sets={'one'}, elems={'m', 'h', 'c', 'e', 'k', 'a', 'g', 'l', 'b'}),
 UpSetSetIntersection(name=three, sets={'three'}, elems={'f', 'h', 'm', 'e', 'i', 'j', 'a', 'g', 'l'}),
 UpSetSetIntersection(name=(one ∩ three), sets={'one', 'three'}, elems={'a', 'm', 'h', 'g', 'l', 'e'}),
 UpSetSetIntersection(name=two, sets={'two'}, elems={'a', 'e', 'j', 'd', 'b'}),
 UpSetSetIntersection(name=(one ∩ two), sets={'one', 'two'}, elems={'e', 'b', 'a'}),
 UpSetSetIntersection(name=(three ∩ two), sets={'two', 'three'}, elems={'e', 'j', 'a'})]
In [7]:
w
Out[7]:
In [9]:
def selection_changed(s, ws):
    # w.selection = ws["name"] if ws else None
    return s, ws # s["name"] if s else None
interact(selection_changed, s=10, ws=w)
Out[9]:
<function __main__.selection_changed(s, ws)>
In [10]:
w.height = 600
w
Out[10]:
In [ ]: