Working With the Editor

Nextjournal offers an intuitive WYSIWYG interface for creating and publishing notebooks. The features covered in this article will make working with code and data more convenient through the use of several powerful features.

Setup

Upload data and load dependencies to illustrate the features in this article.

Data

artwork_data.csv

artwork_data.csv is the complete dataset of the Tate's permanent collection.For more information on uploading data, please see Importing and Exporting.

Dependencies

The demonstration will use pandas to parse artwork-data.csv and figure-factory to create the table. For more information on working with packages in Python or any other language supported on Nextjournal, please refer to How to Install Software and Packages.

import pandas as pd
import plotly.figure_factory as ff

Shortcut Keys

  • Cmd/Ctrl-I, Cmd/Ctrl-B to mark text italic or bold.
  • ↹ Tab, ⇪Shift ↹ Tab to promote or demote headings.
  • ⇪Shift↵Enter in a code cell to run the cell and advance to the next cell. If no cell exists, a new cell of the same type is created.
  • ⇪Shift↑to jump to the code cell above the currently selected cell.
  • ⇪Shift↓to jump to the code cell below the currently selected cell.
  • Use @ (the "at sign") in a code cell to Insert Reference, Import code from a cell, or Import code from a notebook.
  • Use @ (the "at sign") in a paragraph block to insert a Formula, Number, or Data.

Copy and Paste

Cut and paste is easy in Nextjournal. Hover over the artwork_data.csv box above to reveal the ··· action menu. Open this menu and select Copy.

Just as you would in any text editor, paste the contents in the function call of pd.read_csv(). Cmd/Ctrl-V or Right Click → Paste as illustrated in the following code cell:

artwork_data = pd.read_csv(artwork_data.csv)

# Display the first 10 rows and 3 columns of the dataframe
ff.create_table(artwork_data.iloc[:10,[2, 18]], index=False)

artwork_data.csv is actually a Nextjournal reference passed to pandas' read_csv function. When the cell is run, Nextjournal automatically pulls in the data from the .csv file.

References

For the demonstration, grab the first URL in the table above using pandas' iloc index.

artwork_data.iloc[0,18]

Note the URL in the result above. There are two ways of referencing this in another cell.

  • Cut and Paste method: Hover over the URL to reveal a Copy Result button to the left.
  • Insert Reference method: place the cursor inside the urlopen() function and typing an @ to reveal the insert menu. Select Insert Reference and find the URL in the list.

The latter approach is more powerful. You will see several other options in this menu.

However the reference is placed, the following cell takes the tate.org.uk URL, grabs the file off the web, and displays it as the result. To learn more about how to display cell results in Nextjournal, please see Understanding Results.

import shutil
import tempfile 
import urllib.request

with urllib.request.urlopen(nil) as response:
    with tempfile.NamedTemporaryFile(delete=False, dir='/results') as tmp_file:
        shutil.copyfileobj(response, tmp_file) 

with open(tmp_file.name) as html:
    pass