Creating Assignments#

Most courses in CDSS use Jupyter notebooks for assignments. Jupyter notebooks are a tool used for in-browser computing that allow you to include code, text, and visualizations on the same page. Once created, these notebooks can be distributed to students and then downloaded in various formats for submission. You can see an example of a Data 8 notebook here. The link might take some time to download all of the files.

Working with Jupyter Notebooks#

Below is an short introduction on how to use Jupyter notebooks on datahub.berkeley.edu. Assignment development can be done on datahub.berkeley.edu or locally, if you already have a local Jupyter setup. The below steps assume you are working on DataHub, but most of the steps can be done on a local setup as well. If you decide to work locally, we recommend you test your notebooks on datahub.berkeley.edu well in advance. The development environment on DataHub is probably different from your local environment, so it is possible that code may break.

Create a Blank Notebook#

This section describes how to create a notebook on the JupyterHub infrastructure. Go to datahub.berkeley.edu. Click on the green Start My Server button. You will not need to do this if you are working locally.

Click on the New dropdown on the right side of the page. Select the option for Python 3 under Notebooks.

You will see a blank notebook to which you can now add text and code. The notebook consists of sections called cells. There are different types of cells that can be used. Code is part of the “code” cell type and text is part of the “markdown” cell types.

Add a New Cell#

You can add a new cell using eiher the + button on the left side or the Insert button on the toolbar.

To set the type of this cell, click on Cell in the toolbar, then Cell Type and then either Code or Markdown. Code can be directly typed in. Text must be added in markdown format.

Here is an example of what code and markdown cells with content will look like.

You will notice that there is no code output in the previous image. In addition, the text formatting is not properly displayed. To run code or see the formatted text, you must run the cell. An individual cell can be run by typing Shift-Enter from the cell. All cells can be run by clicking the play button in the toolbar (triangle with a line). You can also click on “Cell” in the toolbar for additional ways to run cells. Below is the output of running all cells.

Run Code#

You can run code by either typing Shift-Enter from the cell or clicking the play button in the toolbar (triangle with a line).

Code that has been run in one cell is accessible by another cell. If any changes are made to a cell, you must rerun all cells that you want affected by the change.

Download Notebooks#

Click on File in the toolbar, then Download as, then select Notebook (.ipynb) . This will download the notebook to your computer in the standard Jupyter notebook format. You can also download notebooks in alternate formats, seen below.

Additional Resources#

  • Markdown basics notebook - Double clicking on each cell allows you to see how a variety different content is formatted in Jupyter Notebooks.