How to make HTML slides from ipynb, md, and rmd
The goal of this tutorial is to demonstrate how to make HTML slidedecks that can be put on the web.
Instructions for how to turn Markdown (.md
), R Markdown (.Rmd
), and Jupyter Notebook (.ipynb
) files into slides are detailed below.
One major advantage of HTML slidedecks is that you can host them on GitHub for free and share a url, instead of resorting to email or transferring files using USB drives.
Instead of using Powerpoint, Keynote, or Google Slides, I recommend you try to generate slides programmatically using the steps below.
Speaking of Powerpoint, I suggest that you avoid the horrors of Microsoft Office entirely.
The easiest way to create a slideshow is to write a simple markdown file, like habits.md
, and use Pandoc to convert it to one of the possible HTML formats.
There are many ways to install Pandoc, but I recommend to use Anaconda or Miniconda. The Anaconda installer is hundreds of MB in size because the Anaconda Python distribution includes hundreds of Python packages plus the Anaconda Navigator program. The Miniconda installer is more than ten times smaller and includes only Python and conda.
Once you have Anaconda or Miniconda installed, you can install Pandoc using this command-line command conda install -yc conda-forge pandoc
and then run the one of the options below:
pandoc -t dzslides habits.md -o pandoc/dzslides-pandoc.html --self-contained
pandoc -t slidy habits.md -o pandoc/slidy-pandoc.html --self-contained
pandoc -t revealjs habits.md -o pandoc/revealjs-pandoc.html -sV revealjs-url=https://revealjs.com
Instead of using Pandoc in the terminal as described above, you can also install Pypandoc and convert Markdown to almost any format in your Python environment (e.g. in PyCharm)!
.md
) you want to create, and press Enter again. You get Markdown syntax highlighting and a live preview of your rendered Markdown!.py
to .md
, PyCharm will continue to treat the file like a Python script giving you the ability to run code in your Markdown document! As soon as you take the file out of the Scratches folder, PyCharm will treat it like a Markdown file again! In short, PyCharm will auto-detect the file type based on its extension, but this does not apply to scratch files!First, you will need to install R. Again, I recommend installing Anaconda or Miniconda and then running conda install -yc r r-essentials
.
Then, write you can run one of the commands below to make the html slideshow.
Rscript -e "rmarkdown::render('habits.md', 'ioslides_presentation', 'r/ioslides-r.html')"
Rscript -e "rmarkdown::render('habits.md', 'slidy_presentation', 'r/slidy-r.html')"
You can also install RStudio by running conda install -yc r rstudio
, open up a markdown file in RStudio, add a YAML header that specifies the output_format
as in habits.Rmd
, save the file and then click Preview/Knit or Press Ctrl/Cmd + Shift + K.
For revealjs and xaringan slides, you must first run install.packages('revealjs')
and install.packages('xaringan')
in RStudio before you can Knit (Ctrl/Cmd + Shift + K).
You only need to install the packages once!
You can also run install the packages and render slides from the command-line as below:
Rscript -e "install.packages('revealjs', repos='http://cran.us.r-project.org')"
Rscript -e "install.packages('xaringan', repos='http://cran.us.r-project.org')"
Rscript -e "rmarkdown::render('revealjs.Rmd', output_file = 'r/revealjs-r.html')"
Rscript -e "rmarkdown::render('xaringan.Rmd', output_file = 'r/xaringan.html')"
You can also create slides from a Jupyter Notebook using jupyter nbconvert
.
If you have Anaconda installed, you should already be able to run jupyter nbconvert
, but if you are using Miniconda you will need to install nbconvert
by running conda install -yc conda-forge jupyter nbconvert
.
url="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.5.0"
jupyter nbconvert revealjs.ipynb --to slides --reveal-prefix=$url
Or
jupyter nbconvert revealjs.ipynb --to slides --reveal-prefix="https://revealjs.com"
Another way to create slides is to open the Jupyter Notebook in JupyterLab and follow the instructions in this example slide deck:
Both of the methods above should give the same result: a revealjs html slideshow file.
There are other ways to make slides from a Jupyter Notebook that do not involve making an html file.
These two options are not the same as creating an html slideshow from a jupyter notebook and hosting it on your website, but they get the job done.