Reputation: 1003
I have a list of csv files from glob.glob
. Each csv is used to generate a figure. I would like to use an ipywidget dropdown menu so that only the file that is selected is plotted.
import glob
import pandas as pd
import ipywidgets as widgets
from IPython.display import display
from IPython.html.widgets import interactive
csvs = sorted(glob.glob('*/*csv'))
for csv in csvs:
df = pd.read_csv(x, sep=',')
plt.figure()
df.plot()
The dropdown menu would therefore be
w = widgets.Select(options=csvs)
display(w)
It would also be ok to use widgets.Button
if this is the only way. Thanks!
Upvotes: 1
Views: 3247
Reputation: 1003
Finally got it
import glob
import ipywidgets as widgets
from IPython.display import display
from IPython.html.widgets import interactive
csvs = sorted(glob.glob('*/*csv'))
def plot(x=csvs[0]):
dfs = pd.read_csv(x, sep=',')
dfs.plot(figsize=(12, 8))
w = widgets.Select(options=csvs)
interactive(plot, x=w)
Now does anyone know why the widget isnt kept when I export the notebook to html?
Upvotes: 3