Sending data from a web app to an ipython notebook - python

We have a web app that allows users to interactively discover web service data URLs. We would like to allow a discovered service URL to be sent to an Ipython Notebook, where data from the service could be extracted, analyzed and visualized in the notebook. Is that possible?

This topic : Connecting to a remote IPython instance
will show you how to execute python code from an app/script and return any "python objects" back to the notebook kernel.
Essentially what i will do in this case is to execute python code from the web app using the approach described before, note that for recent version of IPython (i use 3.0-dev) you should change :
from IPython.zmq.blockingkernelmanager import BlockingKernelManager
to :
from IPython.kernel import BlockingKernelClient
If your web-app can receive parameters in the url, you can construct the url+query from the notebook giving the connection info as one of the input parameters.
You can retrieve the connection ifo within the notebook using:
%connect_info

Related

VS Code connecting to jupyterlab server not selecting kernel

We have recently moved to a JupyterLab Server from another IDE. We are trying to get VS Code hooked up so that we can code in it rather. After much struggle, we got VS Code to connect to our remote JupyterLab server. On the status bar in the bottom, it shows
However, as soon as we connect to the JupyerLab server, all the 'run' buttons on screen disappears.
We are getting no support from our IT and have to figure it out ourselves.
A colleague suspects that it (VS Code) is not picking up the python kernel from the server. How do we go about selecting it? or pointing to it?
An additional question, how do we see and browse the folders on the JupyterLab server in VS Code?
Appreciate any assistance
I think the problem is that you didn't really connect to the remote server.
Install Remote-SSH extension. Then you can see the button on the bottom left. Click and you can connect to your service and view your folder.
You can read document about Remote-SSH for more details/
Connect to a remote Jupyter server.
According to the document about jupyter, you have to do the following steps:
Open the Kernel Picker button on the top right-hand side of the notebook (or run the Notebook: Select Notebook Kernel command from the Command Palette).
Select the Existing Jupyter Server option to connect to an existing Jupyter server.
To connect to an existing server for the first time, select Enter the URL of the running Jupyter server.
When prompted to Enter the URL of the running Jupyter server, provide the server's URI (hostname) with the authentication token included with a ?token= URL parameter. (If you start the server in the VS Code terminal with an authentication token enabled, the URL with the token typically appears in the terminal output from where you can copy it.) Alternatively, you can specify a username and password after providing the URI.

Run local code in the Jupyter notebook on remote server via kernel

I want to run local code using local data on a remote server and get back execution results back to my Jupyter notebook cells.
Not usual scheme "run Jupyter notebook remotely, connect to remote notebook via ssh tunneling" but more sophisticated via custom remote kernel which I may choose from the kernel list, and run local code on remote server seamlessly.
Some packages (like this -- https://pypi.org/project/remote-kernel) mention that it is possible, but look dated and come with limited usage instructions.
Anyone knows how to implement this? If so, be as more detailed as possible, thanks!

How to run a google Colab Notebook from terminal?

Suppose I have a Google Colab Notebook in an address like below:
https://colab.research.google.com/drive/XYZ
I want to keep it running for 12 hours, however, then again I want to turn my computer off. As a solution, I can connect to our Lab's server via ssh. The server is running all the time. I would like to know if it's possible that I load and run the notebook there?
I found a solution to connect to a Google Colab Session via ssh (colab_ssh package), but it again needs a running Colab Session.
I also tried to browse the link with lynx, but it needs login and this isn't supported by this browser.
Yes, it is possible. You would first need to download your colab notebook as an .ipynb file, then copy it to your server. Then, you can follow one of the guides on how to connect to a remotely running jupyter notebook session, like this one. All you need is the jupyter notebook software on your server, and an ssh client on your local computer.
Edit: I forgot to mention this: To keep your session alive even after closing the ssh connection, you can use tools like screen. The link provides more detailed explanation, but the general idea is that after connecting to your server, first you need to create a session like this:
screen -S <session_name>
which will create a new session and attach you to it (which is the term used when you are inside a session). Then, you can fire up your jupyter notebook here, and it will keep running even after closing the ssh connection. (You just have to make sure you don't kill the screen session using Ctrl+a followed by k)
Now, you have an indefinitely running jupyter notebook session on your server. You can connect to it via
ssh -N -f -L localhost:YYYY:localhost:XXXX remoteuser#remotehost
as mentioned in the first linked guide, use the browser to run a code cell on your jupyter notebook, and then turn off your laptop without worrying about interrupting your notebook session.

flask bokeh server- figure does not render (ubuntu) but works on local machine

I've created a bokeh plot that is accessible through Flask. I am able to successfully run bokeh server through flask on my local machine via
bokeh server bokeh serve--allow-websocket-origin=localhost:5000 filename.py
flask python run.py on two command windows
Now I want to do the same thing but on a virtual machine running ubuntu. Using the exact same commands on two putty windows no longer work. I am able to access non-bokeh html pages though.
When trying to access the bokeh plot, I get:
OSError: Cannot pull session document because we failed to connect to the server (to start the server, try the 'bokeh serve' command)
but I already intitiated bokeh serve
this is the code snippet in flask that will call bokeh server
#main.route("/grid")
def bokehserver():
session=pull_session(url="http://localhost:5006/filename")
bokeh_script=autoload_server(None, url="http://localhost:5006/filename",session_id=session.id)
return render_template("bokserv.html",bokeh_script=bokeh_script)
edit: I'm reading something about 'linux server configuration files' for running bokeh server on linux. I have not made such configuration files. Can someone confirm whether these are totally necessary? I don't want to overstuff my project with excess. In many examples I've seen, the developer uses nginx and gunicorn and other things to get flask/bokeh up and running, but so far I've been able to avoid these extra layers..
edit2: bokeh serve --show filename.py in the ubuntu terminal generates the standard messages as if it is working but it doesn't open the browser to display the figure.
I created the configuration files referenced in the initial post and used bokeh serve --allow-websocket-origin=(my ip):5000 filename.py.
Then in the flask file from werkzeug.contrib.fixers import ProxyFix
then outside of the app.route(/) i put app.wsgi_app=ProxyFix(app.wsgi_app)
then I navigated to (my ip):5000
and it worked.

Google Drive Quickstart Python - Localhost didn't send any data

I've been following this guide:
https://developers.google.com/drive/v3/web/quickstart/python
and did everything up to the
python quickstart.py
part. When I do that it opens up a new browser (oddly not my default browser but whatever) and I get the OAuth screen, but once I click "Allow" it gives me a "localhost didn't send any data" error. The shell has:
/Library/Python/2.7/site-packages/oauth2client/_helpers.py:255:
UserWarning: Cannot access /Users/timothy.tran/.credentials/drive-
python-quickstart.json: No such file or directory
warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
0:297: execution error:
What does this mean and how can I fix it?
It means it cannot access this file:
Cannot access /Users/timothy.tran/.credentials/drive-
python-quickstart.json
because:
No such file or directory
I just got this quickstart running a while ago. When you click the oauth link generated by python commandline and it opens a random browser, copy that link and paste it in the browser where your gmail account (which you're also using in your google dev console) is currently logged-in. Let me know if you're still stuck after this.
Also I don't think you need a localhost to run this. If anything, I'd used a python virtual environment.

Categories