how to make download link in jupyter appmode

Solutions on MaxInterview for how to make download link in jupyter appmode by the best coders in the world

showing results for - "how to make download link in jupyter appmode"
Ocean
21 Oct 2017
1from ipywidgets import HTML
2from IPython.display import display
3
4import base64
5
6res = 'computed results'
7
8#FILE
9filename = 'res.txt'
10b64 = base64.b64encode(res.encode())
11payload = b64.decode()
12
13#BUTTONS
14html_buttons = '''<html>
15<head>
16<meta name="viewport" content="width=device-width, initial-scale=1">
17</head>
18<body>
19<a download="{filename}" href="data:text/csv;base64,{payload}" download>
20<button class="p-Widget jupyter-widgets jupyter-button widget-button mod-warning">Download File</button>
21</a>
22</body>
23</html>
24'''
25
26html_button = html_buttons.format(payload=payload,filename=filename)
27display(HTML(html_button))
28