I’ve been exploring different mechanisms to post Python Jupyter notebook files on WordPress. Of course, I can use
nbconvert to convert my notebook files to other formats – including HTML – right from the command line. I can then post this file as part of an embedded HTML block in a WordPress post. However, this sounded like an unnecessary step, since I also wanted the notebook to be available in GitHub. I did not want to deal with generating this HTML file AND also managing a published notebook on GitLab as well. Smells a lot like duplicate efforts, wasted time. Thanks to a great WordPress plugin from Andy Challis, called nbconvert, I was able to achieve what I wanted! See his page at https://www.andrewchallis.co.uk/portfolio/php-nbconvert-a-wordpress-plugin-for-jupyter-notebooks/ for complete instructions.
- If you haven’t yet, you must install WP Pusher as a plugin in your WordPress site. (See this for more info.)
- Go to his web page for nbconvert, copy the CSS custom code displayed on the page.
- Go to your WordPress page, and add the custom CSS displayed on the page above into Appearance -> Customize -> Additonal CSS
- Go to https://github.com/ghandic/nbconvert and verify the latest instructions. Install the nbconvert shortcode plugin through WP Pusher. Activate it.
- That’s it!
Follow the instructions to include your own Jupyter notebook file available on GitHub.
Here is an example. In a standalone text (or paragraph) block, I included the following shortcode:
[nbconvert url="https://github.com/bkingcs/python_snippets/blob/master/clustering/hierarchical.ipynb" /]
This generates the following: