Friday, 13 May 2016

Jupyter Notebook with Django

Introduction


To start with, I am a Python and Django lover and like to stay in Python for as long as I can while programming. It's so smooth to code in Python, it almost flows by itself. For Web Development, I've used various platforms like native PHP, CakePHP Framework and Django, and out of these Django remains my favourite. I just came across this amazing thing called Jupyter Notebook, an IDE sort of thing right in your browser. What's amazing is that, you can write python code just like you would do in a normal python shell, and see the results right inside your browser. The key thing to notice is that if you are going to do some data visualizations, such as plotting some data using Bokeh, you can view it in no time and make changes to your code: all inside your browser. The best part: Vim, Sublime and Emacs like editing modes are available too!

Configuring Jupyter Notebook for Django


->To set up Jupyter with Django, make sure that Django and Jupyter are installed on your system. You can update them by typing:
pip install --upgrade django jupyter

->Then, you need to install django extensions:
pip install django-extensions

->Install bokeh and pandas (optional):
pip install bokeh pandas

->Create a django project by typing:
django-admin startproject dummyProject

->Open the settings.py file for the project in vim (or any other editor) by typing:
cd dummyProject/dummyProject
vim settings.py

->Inside the INSTALLED_APPS list, type 'django_extensions', so it looks something like this:
INSTALLED_APPS = (
    ....
    'django_extensions',
)

->Type the following command to open the Jupyter Notebook:
cd ../
python manage.py shell_plus --notebook

This will start a server and open the Jupyter Notebook in your default browser.

->Click on New->Django Shell-Plus to open up an interactive python shell where you can type in commands. To execute a command, type it and press Shift+Enter. You can even copy and paste data to and from this shell.



->To open up a terminal inside your browser, go to Home page of the notebook, click on New->Terminal.

Here is a screenshot of a random visualization with Bokeh in Jupyter Notebook:





That should give you a fair idea about where to start. To explore the Jupyter notebook, read the official documentation here.

No comments:

Post a Comment