Create branded slides directly from your python code

A customisable template for outputting your data via python without having to worry about copying data and formatting in PowerPoint using Quarto.

A customisable template for outputting your data work with stakeholders via python without having to worry about copying data and formatting in PowerPoint using Quarto.

What is Quarto and why should you use it?

Quarto lets you create your presentations automatically from a combination of text via markdown and graphs / tables via code directly from your data. If you have previously used RMarkdown then Quarto works exactly the same way but now lets you code directly in python without having to use reticulate. Note both Quarto and the below template both work with other languages like R but this post will focus on how to do this with python.

Because your graphs are now created by code it makes it easier to update the presentation quickly.

How many times have you presented your work to your stakeholder and they liked the work but asked for a different segment of the data or 6 months after they originally asked for the work they want an updated version. When doing this via Quarto you only need to re-filter your data in your code and then automatically regenerate the presentation (with updated commentary if needed).

On top of this what makes Quarto great is the ability to create a reusable theme for your brand.

This then means that you no longer have to worry about the formatting of your PowerPoint presentation at all. This will enhance the impact of your analysis without spending a portion of your limited time on the formatting.

Introducing the customisable theme

This git repo is a python package that has:

  • A theme for Quarto to create presentations via revealjs
  • A theme format your graphs with plotnine along with supporting functions to improve the ability to format text on your graphs / titles. For those that aren't familiar with plotnine it is ggplot in python and is the best graphing package in my opinion for python. Plotnine allows you to build up a graph from components and makes complex graphs simple to code.
  • A cli function to add the template to a python project. A Quarto theme consists of a number of files and this function will automatically copy everything into the your working directory.

This has been designed in a way that its supposed to be customised from a single yaml file without having to spend the time learning and reading the docs on how to format each of these components yourself. Then packaged to create your own version of the template that matches your existing brand.

Quarto theme

The theme is created through revealjs presentations and formatting is customised through CSS. Of all the different ways you can create presentations with Quarto revealjs is the one that has the easiest customisation.

As revealjs creates a html presentation when rendered by Quarto I've also created presoutput which will convert the html file into either a PDF or PPTX file through either the command line (presoutput <qmdfilename.qmd>) or a python script (qmd_to_pdf() or qmd_to_pptx()).

Quarto example

The below code is an example of how you would generate the outline of your presentation. A new slide is denoted by ## and then text is written straight into the qmd file. Inside this you can add code cells to output code and graphs in your slides see the complex example of how this works.

---
title: Slide title goes here
subtitle: Slide subtitle goes here or delete this line
author: Author name goes here
format:
  brandtemplate-revealjs:
    toc: false
---

## Introduction Slide

This is an example to show you how you can quickly create slides in Quarto.

## Section page {.section-slide}

## Slide with single column

#### Section title

Text of the slide goes here.

## Slide with subheading

### Subheading goes here

#### Section title

Text of the slide goes here.

## Thank you {.thank-you-slide}

Then it's as simple as running the following in the command line presoutput <qmdfilename.qmd> to create a pdf document or presoutput <qmdfilename.qmd> -t pptx to create a pptx document from your code.

You can see the output of the simple and more complex outputs here and see the full code [here] (https://github.com/aplunket/brandtemplate-example).

Plotnine functions

By default the graphs in plotnine are cluttered and could be formatted better. This can be fixed by creating a theme. The package includes a theme for plotnine alongside functions to better aligned titles with the ability to include multicoloured text.

See the full list of functions in the repo

Importing the template via cli

As the template contains various css, font and background images that you would need to copy into each of your projects I have created a function so that you can quickly import everything you need. All you need to do is run brandtemplate-import in the command line of your project.

Note: if you rename this in the customisation section the brandtemplate will be replaced with what you rename the package to.

How to customise the theme

I've made the theme simple to customise via a config yaml file so you don't need to worry about learning how to do this yourself. All you need to do is:

  1. Fork the git repo (https://github.com/aplunket/brandtemplate)
  2. Update config.yaml in template_config to update the formatting of the template.
  • If changing the fonts add the new font files into brandtemplate/template_files/font and delete the existing files.
  • Change the background and logo image files in brandtemplate/template_files to the ones for your brand. These can be copied out of your PowerPoint template and saved as an image.
  1. Run python template_config/template_config.py to update the template based on the changes to your config.yaml.
  2. Make any changes to PACKAGE.md to update the documentation for how to install the package if using a private repo.

Deploying the theme as a package

This has been set up so that once you have customised this theme for your brand then it can be packaged and deployed to your internal python repository (or installed directly from the build files).

To do this all you need to do is run poetry build and then publish using poetry publish. Note: before publishing read the poetry documentationon how to set up a private repository with poetry.

Subscribe to Andy Plunket

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe