Skip to content
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 demo of use Jupyter Notebook for lesson #94

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ MAKEFILES=Makefile $(wildcard *.mk)
JEKYLL=jekyll
PARSER=bin/markdown_ast.rb
DST=_site
JUPYTER=jupyter

# Controls
.PHONY : commands clean files
.NOTPARALLEL:
all : commands

## commands : show all commands.
commands :
@grep -h -E '^##' ${MAKEFILES} | sed -e 's/## //g'

## serve : run a local server.
serve : lesson-md
serve : lesson-rmd lesson-jupyter
${JEKYLL} serve

## site : build files but do not run a server.
site : lesson-md
site : lesson-rmd lesson-jupyter
${JEKYLL} build

# repo-check : check repository settings.
Expand Down Expand Up @@ -54,12 +54,16 @@ workshop-check :
## ----------------------------------------
## Commands specific to lesson websites.

.PHONY : lesson-check lesson-md lesson-files lesson-fixme
.PHONY : lesson-check lesson-rmd lesson-files lesson-fixme

# RMarkdown files
RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))

# JUPYTER files
JUPYTER_SRC = $(wildcard _episodes_ipynb/??-*.ipynb)
JUPYTER_DST = $(patsubst _episodes_ipynb/%.ipynb,_episodes/%.ipynb,$(JUPYTER_SRC))

# Lesson source files in the order they appear in the navigation menu.
MARKDOWN_SRC = \
index.md \
Expand All @@ -80,16 +84,17 @@ HTML_DST = \
$(patsubst _extras/%.md,${DST}/%/index.html,$(wildcard _extras/*.md)) \
${DST}/license/index.html

## lesson-md : convert Rmarkdown files to markdown
lesson-md : ${RMD_DST}
## lesson-rmd : convert Rmarkdown files to markdown
lesson-rmd: $(RMD_SRC)
@bin/knit_lessons.sh $(RMD_SRC)

# Use of .NOTPARALLEL makes rule execute only once
${RMD_DST} : ${RMD_SRC}
@bin/knit_lessons.sh ${RMD_SRC}
## lesson-jupyter : convert Jupyter Notebook files to markdown
lesson-jupyter: $(JUPYTER_SRC)
${JUPYTER} nbconvert -y --execute --allow-errors --to markdown --output-dir=_episodes --NbConvertApp.output_files_dir="" --template=_layouts/ipynb2md.tpl $(JUPYTER_SRC)

## lesson-check : validate lesson Markdown.
lesson-check :
@bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
@bin/lesson_check.py -s . -p ${PARSER}

## lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace.
lesson-check-all :
Expand Down
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ exclude:

# Turn off built-in syntax highlighting.
highlighter: false

kramdown:
parse_block_html: true
111 changes: 111 additions & 0 deletions _episodes/07-jupyter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
title: Using Jupyter Notebook
teaching: 10
exercises: 1
questions:
- "How to write a lesson using Jupyter Notebook?"
objectives:
- "Explain how to use Jupyter Notebook with the new lesson template."
- "Demonstrate how to include pieces of code, figures, and challenges."
keypoints:
- "It shouldn't be difficult"
---

The lesson should be written with a mix of code cells and Markdown cells,
just like you'd normally do.


~~~
1 + 1
~~~
{: .source .python}



~~~
2
~~~
{: .output}


Output with error message:


~~~
x[10]
~~~
{: .source .python}

~~~
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-2-7644c71c757c> in <module>()
----> 1 x[10]

NameError: name 'x' is not defined
~~~
{: .error}
Output generating figures:


~~~
% matplotlib inline
~~~
{: .source .python}


~~~
import matplotlib.pyplot

matplotlib.pyplot.plot([1,2,3], [1,2,3])
~~~
{: .source .python}



~~~
[<matplotlib.lines.Line2D at 0x7f542455f208>]
~~~
{: .output}




![png](../07-jupyter_6_1.png)

For the challenges you need to pay attention
to include `<blockquote class="challenge">` before it
and `<\blockquote>` after it.
And for the solutions you need to pay attention
to include `<blockquote class="solution">` before it
and `<\blockquote>` after it.
**This hacks is necessary for allow include Jupyter cells on challenges and solutions.**
<blockquote class="challenge">
## Challenge: Can you do it?

What is the output of this command?

~~~
"a" + "b"
~~~
{: .source}

<blockquote class="solution">
## Solution


~~~
"a" + "b"
~~~
{: .source .python}



~~~
'ab'
~~~
{: .output}


</blockquote>
</blockquote>
Binary file added _episodes/07-jupyter_6_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
Loading