When you first log in to your Jupyter Notebook environment, you'll be presented with a screen that shows the contents of your personal directory on the DataHub server or your home directory on your local computer. This directory, or tree view as Jupyter calls it, should look like the image below.
From here you can click on the
New button, and select
This will open a new tab or window with a new Python Notebook file in the editor, named by default as
You can click into the title
Untitled and rename your notebook to something more descriptive. For example,
mynotebook. Jupyter will add the file extension
.ipynb automatically for you.
If you go back to the tab or window with the directory view, you'll see the notebook is also renamed, and the icon for it is now green with the status of
A running notebook means it is connected to the server which will run any of the code it contains. The NCSSM DataHub is configured to shutdown any notebooks that don't have activity for awhile to save on processing time and memory. You may have to reconnect to the server, or kernel, if your open notebook sits idle too long. You can also manually shutdown your notebook by checking the box next to the notebook in the directory view, which will reveal the options to Duplicate, Shutdown, View, Edit, or Delete the selected notebook.
Let's switch back over to the notebook.
Every Jupyter Notebook consists of cells. The first empty cell is already available to you after creating the notebook. You can see by clicking into the cell that this cell is for writing code, as indicated by the drop down box in the menu bar. You can toggle the way a cell works by selecting: Code, Markdown, or one of the other listed choices. MA/CS 358: Cryptography will only use Code and Markdown type cells.
A code cell is a place to write and run instructions written in the selected programming language, in this case Python 3. You can execute the code in a cell by either clicking the run button in the menu bar or by pressing
shift + enter on your keyboard. Doing so will also advance you to the next cell, or if there isn't a next cell, create a new empty cell. Pressing
ctrl + enter will execute the code and keep the run cell selected. Any of these methods are fine, but you may find certain circumstances when you prefer one of the other.
In the following sections we'll see examples of code that can be executed in these types of cells.
You can change the cell type from Code to Markdown to include explanatory text, tables, links, and/or images in your notebook.
Markdown is a lightweight markup language with plain text formatting syntax. Its design allows it to be converted to many output formats, including HTML within a Jupyter Notebook. This means that you can quickly mark a passage of text as a heading, subheading, link, or other content that your notebook will automatically know how to format.
For example, copy and paste this Markdown code into a cell and running it.:
# This is a Heading ## This is a subheading *This text will be italics* __This text will be bold__ * Bullet point 1 * Bullet point 2
You should see that your notebook was able to understand that the symbols
__ have a special meaning when placed near or around text, and formatted the text accordingly.
For a cheat sheet on the Markdown syntax, use this resource (https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) for many common formatting choices.
Occasionally you may want to share the work you've completed in your notebook. Choosing the
File -> Download as choice from the menu bar brings up a variety of choices to save and share your work in.
- Notebook (.ipynb): This option will allow someone else to open your notebook in Jupyter and edit/run your cells on their own.
- Python (.py): This option will remove your markdown cells and put all the code cells into a single file that can be run all at once. This option is for cases when you just want to run the code and don't need the added context of your Markdown cells.
- HTML (.html): This option will convert your notebook into a static HTML webpage that preserves all your cells and their outputs, but will not allow the viewer to edit or run the cells. This is best for when you only want to provide a view only option.
- Markdown (.md): Same as HTML, but all cells are in the Markdown format.
- PDF (.pdf): Same as HTML, but in a PDF format.
- Latex (.tex): Same as HTML, but in a LaTeX format.
When you are done using a notebook, it's good practice to close the tab that it's in, shutdown the notebook from your directory view, and then log out from the DataHub. This will free up any resources currently allocated to you for others to use. The good news is that even if you forget, the DataHub will shutdown your notebooks and log you out automatically if too much time passes without any activity.