Gregor Koehler / Jan 19 2018

Getting Started with Nextjournal - edit

Nextjournal supports server-side execution of Julia, Python, R, Clojure and Bash. In the browser, you can code in ClojureScript and JavaScript.

This document is actually a copy of the original guide. Let's start with a simple but common use case — uploading a data file and plotting its contents using Python and Plotly.

1.
Uploading data files

Like everything else in a document, files can be inserted anywhere using the insert menu.

iris_data.csv
Download

2.
Writing code in cells

Code lives in discrete, language-specific cells. By default, all cells of the same language run in the same execution runtime. Learn more about runtimes further ahead.

All articles ship with useful packages for data processing. Let's insert a Python cell and import the handy Pandas library to work with our dataset.

import pandas as pd
import numpy as np

3.
Accessing uploaded files

We can read our dataset using Pandas' read_csv and store it as a DataFrame. To reference our uploaded file, we'll just type it's name to see it autocompleted.

Here we can see that and output from the cell shows up underneath it.

iris_df = pd.read_csv(iris_data.csv)
print(iris_df

4.
Plotting data

Now let's set some column names on the data and plot it using Nextjournal's built-in Plotly support.

column_list = ['Sepal Length', 'Sepal Width', 
               'Petal Length', 'Petal Width', 'Iris Type']

iris_df.columns = column_list

fig_scatter, ax = plt.subplots()
for iris_type in iris_df["Iris Type"].unique():
  ax.scatter(x=iris_df["Sepal Length"].loc[
    					iris_df["Iris Type"]==iris_type], 
             y=iris_df["Sepal Width"].loc[
    					iris_df["Iris Type"]==iris_type], label=iris_type)
ax.legend()
ax.grid(True)
plt.xlabel("Sepal Length")
plt.ylabel("Sepal Width")

fig_scatter

5.
Installing packages

Let's look at how we can clean up this data and write it to a file. We'll use the scikit-learn package, which offers good collection of preprocessing tools. We'll install it in a bash cell using the pip package manager.

pip install scipy