I build a ipywidget button. I hope that when the button is clicked, the program do the computing, and get a result string, then user can download the string as a file.
THe codes are like this:
import ipywidgets as widgets
download_button = widgets.ToggleButton()
download_button.on_click(do_some_work)
def do_some_work(content)-> str:
res = compute()
# Here comes the problem: how to let user download the res as a file?
def compute()-> str:
# ... do_some_compute
return res
I have read ipywidgets doc for plenty times, but could not find a solution.
I use an alternative way now (which seriously affected the user experience): create a HTML widget and when download_button is clicked, change the value of HTML widget to an link to data:text/plain;charset=utf-8,{res}
to let user click and download, but is there any way to achieve this with single one click?
Any help will be much appreciate.