#!/usr/bin/env python # coding: utf-8 # ## For SO https://stackoverflow.com/q/78619042/8508004 'How to load data using ipywidgets and make it available for Download' # # Developed in sessions launched from [here](https://github.com/fomightez/3Dscatter_plot_mod_playground-binder) and served via the MyBinder service. Go there and click on a 'launch binder' badge. # In[4]: get_ipython().run_line_magic('pip', 'install openpyxl') # In[1]: # use any example xlsx as staring point; this was near top when I googled 'sample .xlsx file' get_ipython().system('curl -OL https://github.com/frictionlessdata/datasets/raw/main/files/excel/sample-1-sheet.xlsx') # In[14]: import ipywidgets as widgets from IPython.display import display output = widgets.Output() import pandas as pd def load_data(): df = pd.read_excel('sample-1-sheet.xlsx',engine='openpyxl',dtype=str) with output: output.clear_output() # from 'Output widgets: leveraging Jupyter’s display system' https://ipywidgets.readthedocs.io/en/latest/examples/Output%20Widget.html display(df) def on_sample_data_click(event): load_data() text_caption = widgets.HTML(value="

Showing data

") vbox_text = widgets.VBox([text_caption]) display(vbox_text) load_sample_data = widgets.Button(description='Click to show', layout=dict(width='auto', height='auto')) load_sample_data.on_click(on_sample_data_click) display(load_sample_data) display(output) # In[ ]: