{ "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 the 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": [ "## Running code in a notebook" ] }, { "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", "The code in Jupyter notebooks is contained in cells, or boxes, on the page – you can identify code cells by the borders around them. \n", "\n", "To run code snippets:\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", "\n", "That's it – try it with the cell below!" ] }, { "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}')\n", "\n", "# Hey! Have you noticed that lines starting with '#' are comments? They can help you understand what's going on in the code." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
Help! Nothing happens when I click!
\n", "\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 with your name!
\n", "\n", "Help! I get a weird error saying 'require is not defined', or a message saying something about 'Vegalite'.
\n", "If you're using Altair in Jupyter Lab rather than Jupyter Notebook, you need to make an adjustment to the code above. Just change 'notebook' to 'default' in the line starting 'alt.renderers.enable' and run the cell again.
\n", "\n", "