I am working with a Jupyter Notebook hosted on an external server, i.e. the user has no access whatsoever to the server except through his Jupyter Notebook. I am looking for a way that a user working in such a Jupyter Notebook can download his results as a file directly served from the Jupyter server.
Here is a small example to illustrate what I want to achieve:
# this code runs inside a Jupyter Notebook
import pandas as pd
testdata = { 'a' : [1,2,3,4],
'b' : ['Hotel', 'Bed', 'Beer', 'TV']}
dataset = pd.DataFrame(testdata)
I am looking for a user friendly way to download this dataset (usually the user is doing a lot of processing, reshaping before he is ready to download the data).
For example like this:
mytools.download_dataframe_as_hdf(dataset)
or
dataset.to_hdf('test.hdf', 'test')
mytools.download_file('test.hdf')
Is there a built-in functionality or a neat way to achieve this?
EDIT: Improved the simple solution.
Using HTML
from IPython.display` makes it easy to display a link once the file exists on the file system of the server.
from IPython.display import HTML
HTML('<a href="test.hdf">download hdf</a>')
However, I would like to find a solution to serve the data via a buffered stream, i.e. avoiding to dump the data on the local filesystem first. Any ideas how this functionality could be achieved in a pythonic way?