Notebooks

The notebook puts written text, code and its results in one document, for the weekly reports, investigations and worked analyses that someone runs again and again. Markdown cells hold the explanation; JavaScript cells run in the browser, inside a worker in a sandboxed frame that can reach neither the page nor the network, and keep their variables from cell to cell. A cell's results show beneath it as text, tables, charts, Markdown, pictures or JSON. The notebook knows which cells read from which, so it can run a cell with the cells it needs, mark the ones a change has put out of date, and run them again.

SQL cells are handed to your page's own run function, with their {{name}} placeholders passed as parameters rather than written into the text, and the rows that come back are kept for the next cells. A parameters cell holds the values a run can be given. Notebooks open from and save to .ipynb files, the format other notebook tools read, and go out as a web page of their own or a PDF with the charts drawn in.

Try it with your own notebooks in confidence: they are opened and run by your browser, on your device. Nothing is uploaded, no copy reaches us or anyone else, and nothing is kept once you close this tab.

A bakery's week, in one notebook

Ashgrove Bakehouse, a made-up bakery with five shops in five made-up towns, looks at each week's sales on a Monday morning. The notebook below makes up a week of sales for six of its lines - the same numbers for the same week - and works out the takings by shop and by day, the best sellers and the shops that threw away more than the waste target allows. Run it, run one cell with only what it needs, tighten the target, and take the week away as a web page or a PDF.

Run all The daily chart, with what it needs Waste target 8%, run again The variables The outline Download as a web page Download the PDF
Keyboard: ↑ and ↓ move between cells, Enter edits one and Esc stops editing; Shift+Enter runs a cell and moves on, Ctrl+Enter runs it, Ctrl+Shift+Enter runs it with the cells it needs. A and B add a cell above or below, M makes it text and Y code, Alt with an arrow moves it and Delete removes it.

SQL cells, answered by the page

The same made-up bakery bakes for cafés, schools and a care home too. Its wholesale order book is a notebook file this page writes for itself - a plain .ipynb, with its SQL cells marked by a %%sql line - and opens below. The SQL goes to the page's own run function, which answers three SELECT statements from a small invented table of shops and another of orders kept in the page, and refuses anything else. Change the parameters, ask it something it does not know, and save the run and read it back in.

Run the queries What the page was asked Orders of 60 loaves or more A statement the page refuses Save as .ipynb and open it again Download the .ipynb file
Keyboard: as above; in the Parameters panel, Tab moves between the values and Enter applies them and runs the cells that read them. The tabs of the side panel move with ← and →.