{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using Jupyter notebooks in the GLAM Workbench" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The GLAM Workbench includes many [Jupyter notebooks](https://jupyter.org/). Jupyter lets you combine text, images, and live code within a single web page. So not only can you read about collections data, you can download it, analyse it, and visualise it – all within your browser!\n", "\n", "While notebooks often include some fairly intimidating looking code, you don't need to understand the code to use them. As explained below, there's just a couple of basic conventions you need to keep in mind when running Jupyter notebooks. Once you've mastered these, you'll be able to use any of the tools or examples in this workbench.\n", "\n", "Of course, once you've developed a bit of confidence, you might want to start playing around with the code. That's how you learn. The GLAM Workbench isn't just a collection of tools, it's a starting point – from here you can explore, extend, and experiment!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Text cells and code cells\n", "\n", "You're currently inside a Jupyter notebook. It might look like any old web page, but there are a number of important differences.\n", "\n", "Jupyter notebooks contain two main components – **text cells** and **code cells**. This is a text cell. As well as ordinary text, these cells can contain things like links, images, and tables. Text cells are used to provide documentation and context.\n", "\n", "[](images/PRG-1258-1-1576.jpeg)\n", "\n", "*Text cells can include images and links. All aboard the PS Jupiter, thanks to the [State Library of South Australia](https://collections.slsa.sa.gov.au/resource/PRG+1258/1/1576)!*\n", "\n", "**Code cells** are easy to identify, as they have boxes around them, like this:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Hi there! I'm a code cell!\n", "\n", "# Lines that begin with a hash symbol, like these, are comments within code.\n", "# They don't do anything, but they help you understand how the code works." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Code cells contain snippets of live, executable code – they **do things**. It's this combination of documentation and real, live code examples that make Jupyter notebooks so useful. You can learn by doing!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Running a code cell" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Most of the notebooks in the GLAM Workbench include snippets of real code. You can use this code to do things like download data, or create charts. The programming language used here is [Python](https://www.python.org/). It's popular in the data sciences and is generally pretty easy for humans to understand. \n", "\n", "To run code cells:\n", "\n", "1. Click on the code cell (you'll see the cell becomes highlighted).\n", "2. Hit **Shift+Enter** (the code will run and you'll be moved on to the next cell).\n", "3. If the code cell generates an output, such as text or data, it'll be displayed below the cell.\n", "\n", "\n", "\n", "That's it – try it with the cell below! If all goes well, you should see a message with today's date." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# CLICK ON ME AND THEN HIT SHIFT+ENTER!\n", "\n", "# This makes the datetime module available to use\n", "import datetime\n", "\n", "# This creates a variable called 'date_now' and uses the datetime.date.today() function to set it to today's date.\n", "date_now = datetime.date.today()\n", "\n", "# This displays a nicely-formatted string containing the date\n", "print(f'Congratulations! You ran the code in this cell on {date_now}.')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
Help! Nothing happens when I click!
\n", "\n", "If nothing happens when you click on a cell or hit **Shift+Enter** it's probably because you're viewing a static version of the notebook. See Introduction for setting up a live version.\n", "\n", "Help! I get a weird 'Name Error' saying that 'date_now is not defined.
\n", "If you get a message about a NameError, make sure that you've run the first code cell (where we create the 'date_now' variable, before this one. Most Jupyter notebooks expect you to run cells in order, from top to bottom.
\n", "\n", "Help! I get a weird 'SyntaxError' or 'Name Error'.
\n", "Make sure your name is enclosed in quotes (either single or double, as long as they match). Quotes indicate that you're working with a string or text value. Without them, Python will go looking for a variable labelled with your name!
\n", "\n", "Help! I get a weird 'SyntaxError' or 'Name Error'.
\n", "Make sure your keyword value is enclosed in quotes (either single or double, as long as they match).
\n", "\n", "