Original article was published on Becoming Human: Artificial Intelligence Magazine
A guide to install, configure and use the most useful jupyter widgets.
We can’t thank Project Jupyter enough for bringing in those versatile and interactive IPython notebooks, FOR FREE!. Hands down, jupyter has changed the way experimentation is done using conventional scripts and has become the De facto of modern-day python programming. Why is it so well known? Why is everyone using it? because:
- Each cell can be modified at any point of time even when the program is running.
- Documentation using jupyter notebooks is a cup of tea, export your notebook as a PDF, make it into a python script or export it as an HTML file.
- Complete output is visible for every cell.
- Step-by-Step implementation of complex algorithms makes it easy to progress with the project.
- Jupyter maintains state of notebook therefore code can be undone and deleted cells can be restored.
Now that we know why jupyter is a must, let’s take a look at how we can improve it further to make the experience even more streamlined.
Introducing Notebook Widgets!
Jupyter widgets enhance the jupyter experience by introducing liveliness to your notebooks and are useful for tasks such as easy navigation, smooth presentations, template generation, code formatting and hassle less visualisations. Let’s straightaway dive into it.
Trending AI Articles:
Using condo package manager:
conda install -c conda-forge jupyter_contrib_nbextensions
conda install -c conda-forge jupyter_nbextensions_configurator
Using pip package manager:
pip install jupyter_nbextensions_configurator jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
jupyter nbextensions_configurator enable --user
Now the type following command in terminal and launch jupyter notebook
You must see the following addition in the menu
Uncheck the following button to start using widgets!
Now that you have done that we are ready to go!
For activating a widget search for the name in the search bar as indicated above and check the button.
- Collapsible headings
One of my absolute favourites is collapsible headings widget which allows you to enclose a snippet of code within a heading until next heading of the same size is found. Sometimes the programs get too long and reach to a point where navigation through the code is a tedious task. Use this widget to hide long scripts of code and make your notebook more presentable and easy to understand.
“You primarily write your code to communicate with other coders, and, to a lesser extent, to impose your will on the computer.”
— Guido van Rossum, Python founder
Another widget to make your code more presentable is Autopep8. PEP stands for Python Enhancement Proposal, it is a style for writing python code to make it more readable and understandable. It defines a few formatting conventions such as:
- While writing a function use a lowercase word or words. Separate words by underscores to improve readability — my_func(), prime()
- While declaring a variable use a lowercase single letter, word, or words. Separate words with underscores to improve readability — count, df, first_list
- While declaring a constant use an uppercase single letter, word, or words. Separate words with underscores to improve readability — BASE_PATH,DIMS,ITERATIONS
That’s exactly what Autopep8 does for you automatically! Have a look at the before and after:
All you have to do is just click on the cell you want to correct the formatting of and hit the button below which should be on your jupyter toolbar:
If the task at hand is time consuming then having a widget which can notify user on completing cell execution can be quite handy. One such extension is notify, it basically sends a browser notification every time a cell completes its execution. Say today you have to work on retrieving data from remote databases or perform complex operations on a large dataframe and it is taking so long that you almost forget about its execution, later you check on after an hour and find out it had completed execution half an hour earlier, to avoid the frustration that will follow you can simply use this widget 🙂
Do not forget to allow notifications access to jupyter.
4. Code folding
Like other IDEs such as PyCharm or Eclipse, code folding can also be used in jupyter using the Code folding widget. Here’s an example:
It’s a pretty simple tool and is just plug-and-play, doesn’t require any setup.
Hinterland is an auto-complete extension for jupyter that provides suggestions as you type and it works quite well. If you are among those who tend to write repetitive code for any reason, hinterland is the thing for you!. Look at this demo:
These were some of the most used jupyter widgets to help programmers better manage the code they write, explore more and use those suites you. Do let me know if you find any interesting widgets! Till then, see you next time.
Don’t forget to give us your 👏 !
Top 5 Jupyter Widgets to boost your productivity! was originally published in Becoming Human: Artificial Intelligence Magazine on Medium, where people are continuing the conversation by highlighting and responding to this story.