I'm trying to implement a download button in jupyter notebook (IPython
). I know that button widget do exists in jupyter like below.
from ipywidgets import Button
...
btn_download = widgets.Button(
description='Download',
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltip='Download',
icon='download',
layout=button_layout )
# Then implement download in on_click
def on_button_download_clicked(b):
# Handle download using urlopen
filedata = urllib.request.urlopen(r'file://' + filepath)
datatowrite = filedata.read()
with open("download.fid", 'wb') as f:
f.write(datatowrite)
# Register callback
btn_download.on_click(on_button_download_clicked)
However, this does not seem to work. I have tried few other methods like using urlretrieve
and still won't work.
I am also aware that solution such as using ipython.display.FileLink
exists, but I want to have it in form of button.
Is there any workaround in this?