Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jupyter server dfdata.to_clipboard from remote to local machine. how?

I have a dataframe say dfdata in a jupyter server notebook running on a remote machine).

I want to access the dataframe in the remote machine memory to my local machine, say to paste the dfdata to Excel.

Normally (when the notebook server is running locally), I do dfdata.to_clipboard() to copy the dataframe to clipboard and now able to paste it to Excel.

However, since the dfdata is now on the remote machine, the dfdata.to_clipboard() does not have the copy of the dataframe in clipboard.

How to make this work, i.e. copy paste dataframe from remote machine to locally running Excel, Textfile, etc.? Any alternative methods, if to_clipboard() by design will not work across remote server due to any security restrictions / limitations.

like image 838
ihightower Avatar asked Oct 03 '17 14:10

ihightower


1 Answers

I wrote a Jupyter nbextension to do this (installation instructions in the README).

It overwrites Panda's pandas.io.clipboard.copy & pandas.io.clipboard.clipboard_set (which is an embedded copy of pyperclip) to send messages to the Jupyter frontend via the Comm mechanism. I had to add a simple bootstrap-based UI that pops up when the client-side JS receives a message, as browsers won't let you push data onto the system clipboard without explicit user interaction (security!).

like image 158
Nicholas White Avatar answered Sep 22 '22 02:09

Nicholas White