-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a getting started notebook for jupytext (and Binder) #257
Changes from 3 commits
bae4714
f100eb5
0764de9
9e34354
c0ff979
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,8 @@ python -m bash_kernel.install | |
|
||
# Trust our notebook | ||
jupyter trust demo/World\ population.ipynb | ||
|
||
# Set up extensions for JupyterLab and Notebook | ||
jupyter labextension install jupyterlab-jupytext | ||
jupyter nbextension install --py jupytext --user | ||
jupyter nbextension enable --py jupytext --user | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these two lines are not needed: the notebook extension is already available in the current binder |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Getting started with Jupytext\n", | ||
"\n", | ||
"This small notebook shows you how to activate Jupytext in the JupyterLab\n", | ||
"environment. We'll show you a few things that you can do with Jupytext and\n", | ||
"a bit of what happens under the hood.\n", | ||
"\n", | ||
"**Note: to run this notebook locally, you need to first follow the Jupytext\n", | ||
"installation instructions and activate the JupyterLab plugin. If you're on\n", | ||
"Binder, it should already work.**\n", | ||
"\n", | ||
"## Enabling Jupytext in a new notebook\n", | ||
"\n", | ||
"This notebook is brand new - it hasn't had any special extra metadata added\n", | ||
"to it. \n", | ||
"\n", | ||
"If we want Jupytext to save files in multiple formats automatically,\n", | ||
"we can use the JupyterLab **command palette** to do so.\n", | ||
"\n", | ||
"* Click on the little 🎨 icon to the left\n", | ||
"* Then type **`Jupytext`**. You should see a number of commands come up. Each\n", | ||
" one tells Jupytext to save the notebook in a different\n", | ||
" file format automatically.\n", | ||
"* Select **Pair notebook with Markdown**\n", | ||
"\n", | ||
"That's it! If you have Jupytext installed, it will now save your notebook in\n", | ||
"markdown format automatically when you save this `.ipynb` file.\n", | ||
"\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add something like 'in addition'. It is important to make it clear that Jupyter will continue to save the original notebook as well! Also, maybe we can mention that the two files really point to the same document, and that the Markdown file can be edited as well. |
||
"After you've done this, save the notebook. You should now see a new file called\n", | ||
"**`get_started.md`** in the same directory as this notebook.\n", | ||
"\n", | ||
"## How does Jupytext know to do this?\n", | ||
"\n", | ||
"Jupytext uses notebook-level metadata to keep track of what languages are paired\n", | ||
"with a notebook. Below we'll print the metadata of this notebook so you can see\n", | ||
"what the Jupytext metadata looks like." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import nbformat as nbf\n", | ||
"from IPython.display import JSON\n", | ||
"notebook = nbf.read('./get_started.ipynb', nbf.NO_CONVERT)\n", | ||
"JSON(notebook['metadata'])" | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice example! Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Chris, one meta-question... would you mind if we stored this notebook in its Markdown representation in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ooh that's a cool idea - yeah sounds good There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More explicitly: I was thinking of adding these lines to
|
||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"As you select different languages from the command palette (following the instructions\n", | ||
"above) and save the notebook, you'll see this metadata change." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## That's it!\n", | ||
"\n", | ||
"Play around with different kinds of code and outputs to see how each is\n", | ||
"converted into its corresponding text format. Here's a little Python code\n", | ||
"to get you started:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"\n", | ||
"plt.scatter(*np.random.randn(2, 100), c=np.random.randn(100), s=np.random.rand(100)*100)" | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes me think that we do not have an explicit mention that Jupytext works with every kind of notebook, even the most interactive notebooks with widgets, etc... Maybe we could write a FAQ section in the help and include typical questions like that one. |
||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Experiment with other notebooks\n", | ||
"\n", | ||
"There are several other demo notebooks for you to explore Jupytext's functionality,\n", | ||
"try them out!" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. If we don't include that line, then we get asked if the jupytext extension for jupyterlab should be built, so it's better to do that in advance