python - Jupyter 笔记本下载按钮
问题描述
我正在尝试在 jupyter notebook ( IPython
) 中实现下载按钮。我知道按钮小部件确实存在于 jupyter 中,如下所示。
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)
但是,这似乎不起作用。我已经尝试了一些其他方法,例如使用urlretrieve
,但仍然无法正常工作。
我也知道ipython.display.FileLink
存在诸如使用之类的解决方案,但我想以按钮的形式使用它。
这有什么解决方法吗?
解决方案
推荐阅读
- angular - ngOnDestroy 或 DOM 移除时的 CSS 动画
- javascript - 获取 div 源代码到 HTTP 发布到控制器 ASP.NET MVC
- javascript - 在 Promise 中链接三个查询
- java - 有没有办法用 tomcat 实现 X-Robots-Tag 指令?
- google-analytics - 网站添加到谷歌分析帐户时未填充数据
- c# - 如何使用列表视图显示该安全组中的安全组和用户?
- javascript - 由于使用 onClick 的 textarea 的数据中有空格,因此无法显示 Bootstrap Modal 上的数据
- java - validateOrThrow 实现
- javascript - 将文件从一台设备发送到另一台设备。两台设备都连接到同一个 wi-fi 网络
- mongodb - 配置副本集mongo从localhost到ip