use jupyter widgets to save clicks on a pandas dataframe use jupyter widgets to save clicks on a pandas dataframe pandas pandas

use jupyter widgets to save clicks on a pandas dataframe


It seems VBoxing html displays does a nice job (notice that IPython.display.HTML and ipywidgets.HTML are not the same)

import pandas as pdfrom IPython.display import display, HTMLfrom ipywidgets import Button, HBox, VBox,widgetsimport ipywidgetsdf = pd.DataFrame([[1,'car'],[2,'bus'],[3,'train']])click_list = []button = widgets.Button(description='click')def obc(b):    click_list.append((pd.to_datetime('now'),1)) button.on_click(obc)button2 = widgets.Button(description='click')def obc2(b):    click_list.append((pd.to_datetime('now'),2))button2.on_click(obc2)button3 = widgets.Button(description='click')def obc3(b):    click_list.append((pd.to_datetime('now'),3)) button3.on_click(obc3)display(HBox([VBox([widgets.Button(description=''),button,button2,button3]),ipywidgets.                    HTML(df.style.set_table_attributes('class="table"').render())]))

enter image description here


Is there anyway to automate this? So it can be used with anunknown amount of checkboxes/rows? The code belows gives an errror: AttributeError: 'list' object has no attribute '_handle_displayed'

import pandas as pdfrom IPython.display import display, HTMLfrom ipywidgets import Checkbox, HBox, VBox,widgetsimport ipywidgetsdf = pd.DataFrame(data=[['a',1],['b',32]], columns=['J1','J2'])mydict = {}t=0for ts in df.J1:    mydict[str('c')+ str(t)] =  widgets.Checkbox(value=False, description = 'Accepted')    t=t+1    display(HBox([VBox([widgets.Checkbox(description=''),mydict.values()]),ipywidgets.                    HTML(df.style.set_table_attributes('class="table"').render())]))