A tutorial of fastpages for Jupyter notebooks.
The first cell in your Jupyter Notebook or markdown blog post contains front matter. Front matter is metadata that can turn on/off options in your Notebook. It is formatted like this:
# "My Title"
> "Awesome summary"
- toc: true
- branch: master
- badges: true
- comments: true
- author: Hamel Husain & Jeremy Howard
- categories: [fastpages, jupyter]
toc: true
will automatically generate a table of contentsbadges: true
will automatically include GitHub and Google Colab links to your notebook.comments: true
will enable commenting on your blog post, powered by utterances.The title and description need to be enclosed in double quotes only if they include special characters such as a colon. More details and options for front matter can be viewed on the front matter section of the README.
A #hide
comment at the top of any code cell will hide both the input and output of that cell in your blog post.
A #hide_input
comment at the top of any code cell will only hide the input of that cell.
#hide_input
print('The comment #hide_input was used to hide the code that produced this.')
The comment #hide_input was used to hide the code that produced this.
put a #collapse-hide
flag at the top of any cell if you want to hide that cell by default, but give the reader the option to show it:
#collapse-hide
import pandas as pd
import altair as alt
put a #collapse-show
flag at the top of any cell if you want to show that cell by default, but give the reader the option to hide it:
#collapse-show
cars = 'https://vega.github.io/vega-datasets/data/cars.json'
movies = 'https://vega.github.io/vega-datasets/data/movies.json'
sp500 = 'https://vega.github.io/vega-datasets/data/sp500.csv'
stocks = 'https://vega.github.io/vega-datasets/data/stocks.csv'
flights = 'https://vega.github.io/vega-datasets/data/flights-5k.json'
place a #collapse-output
flag at the top of any cell if you want to put the output under a collapsable element that is closed by default, but give the reader the option to open it:
#collapse-output
print('The comment #collapse-output was used to collapse the output of this cell by default but you can expand it.')
The comment #collapse-output was used to collapse the output of this cell by default but you can expand it.
Charts made with Altair remain interactive. Example charts taken from this repo, specifically this notebook.
# hide
df = pd.read_json(movies) # load movies data
df.columns = [x.replace(' ', '_') for x in df.columns.values]
genres = df['Major_Genre'].unique() # get unique field values
genres = list(filter(lambda d: d is not None, genres)) # filter out None values
genres.sort() # sort alphabetically
#hide
mpaa = ['G', 'PG', 'PG-13', 'R', 'NC-17', 'Not Rated']
# single-value selection over [Major_Genre, MPAA_Rating] pairs
# use specific hard-wired values as the initial selected values
selection = alt.selection_single(
name='Select',
fields=['Major_Genre', 'MPAA_Rating'],
init={'Major_Genre': 'Drama', 'MPAA_Rating': 'R'},
bind={'Major_Genre': alt.binding_select(options=genres), 'MPAA_Rating': alt.binding_radio(options=mpaa)}
)
# scatter plot, modify opacity based on selection
alt.Chart(df).mark_circle().add_selection(
selection
).encode(
x='Rotten_Tomatoes_Rating:Q',
y='IMDB_Rating:Q',
tooltip='Title:N',
opacity=alt.condition(selection, alt.value(0.75), alt.value(0.05))
)