human
I am working on the file "Conversation Analyzer - Basic Stats.ipynb".
The first task is:
Interactive Visualization [WIP]
Can you write Python code for it?
 ... Write me a the Python code you requested?
assistant
#Here is the Python code you requested.

from ipywidgets import interact, widgets

import matplotlib.pyplot as plt
from IPython.display import display, clear_output

%matplotlib inline

hours_basic_stats = conv.stats.generateStatsByYearAndHour(IConvStats.STATS_NAME_BASICLENGTH, stackStats=True)

years = list(map(int, hours_basic_stats['year'].unique()))

@interact(sender=list(map(str, hours_basic_stats['sender'].unique())), 
          stat=list(map(str, hours_basic_stats['stat'].unique())), 
          #year=list(map(str, hours_basic_stats['year'].unique())))
          year=(years[0], years[-1]))
def myplot(sender, stat, year):
    mplot.plotSingleBasicLengthStatByYearAndHour(hours_basic_stats, stat, 
                                                 yearsToShow=[str(year)],
                                                targetSenders=[sender])
    sns.plt.show()

class Dashboard():
    def __init__(self, data):
        self.data = data
        self.selectors = {}
        
    def create_selector(self, target_col, description):
        selector = widgets.SelectMultiple(
            options = list(map(str, self.data[target_col].unique())),
            description = description
        )
        self.selectors[target_col] = selector
        
    def get_selector_values(self, selector_key):
        return list(self.selectors[selector_key].value)
    
    def run(self, fun):
        for k, selector in self.selectors.items():
            selector.observe(fun, names='value')
            display(selector)

d = Dashboard(hours_basic_stats)
d.create_selector('year', 'Year:')
d.create_selector('sender', 'Sender:')

def my_plot(x):
    sns.plt.clf()
    mplot.plotSingleBasicLengthStatByYearAndHour(hours_basic_stats, 'lenMsgs', 
                                                 yearsToShow=d.get_selector_values('year'),
                                                targetSenders=d.get_selector_values('sender'))

d.run(my_plot)