2  Python and Jupyter Notebooks

2.1 About this chapter

  1. Questions
    • How do I write a reproducible analysis document in Python with Jupyter??
  2. Objectives
    • Mix markdown and Python with Rmarkdown
    • Run an interactive analysis document
  3. Keypoints
    • Jupyter notebooks are excellent tools for creating readable, attractive and dynamic reproducible literate programming documents.

2.2 Jupyter Notebooks

A Jupyter Notebook is really quite similar to an RMarkdown document in that it mixes code and markdown in different blocks and allows the user to create a reproducible document. Jupyter varies from RMarkdown slightly in that it prioritises interactive work, instead of rendering a whole document, each block is run individually. Making the whold process a bit more step-by-step than in R Markdown.

2.3 Trying Out Jupyter on The Web

Because Jupyter notebooks are a bit fiddly to get started, there is an online test notebook set up by the Jupyter authors - Classic Jupyter Notebook. It can be a bit busy so may take a few reloads to get started.

For you to do
* Go to the link above and start a classic Jupyter notebook. 
* Work through the `Notebook Basics` section.
* Start a new workbook and play around mixing Python Code and Markdown.
* Save as an html file when you are done

2.4 Starting Jupyter

2.4.1 macOS and Linux

To get Jupyter running on your machine, you need to have Python 3, and the jupyter and ipython packages installed. That is all listed in the set up of this course.

Once those are installed you can start a new notebook server by typing jupyter notebook at the terminal. Depending on the particulars of your local set up you may need to select an appropriate conda environment beforehand. A new server should start showing the filesystem in your web browser, use the buttons in the web page to start a new notebook.

2.4.2 Windows

There should be a Start Menu item that will let you kick off a new Jupyter notebook server. Simply click on that.

For you to do
* Start a new workbook and play around mixing Python Code and Markdown.
* Pay attention to the block type options dropdown in the interface (under the `Widgets` menu), here is where you can tell the document whether you are writing some Markdown or entering Python. Use the `Run` button to run the code/render the Markdown.  
* Save as an html file when you are done
Roundup

Jupyter Notebooks are excellent tools for creating readable, attractive and dynamic reproducible literate programming documents.