Tech Blog

Here I'll be sharing insights from my professional experiences and studies in data science and web development. There'll be plenty of Wagtail, Django and Python, a bit of JavaScript and CSS thrown in, and more on data science & engineering. There might even be a bit of time for some project management and business analysis too.

I'll also provide insights into how this site was made, as well as code examples and thoughts on how those could be further developed.

Feel free to leave questions or comments at the bottom of each post - I just ask people to create an account to filter out the spammers. You won't receive any unsolicited communication or find your email sold to a marketing list.

 
Upgrading to Wagtail 3.0

Upgrading to Wagtail 3.0

Wagtail 3.0 is out with a lot of significant changes in architecture requiring code updates. The biggest work I found was the change in the way custom edit panels are handled in the admin interface which isn't well documented yet. Here are some examples I worked through to get up and running.
2022-05-03 17:09:52 UTC
Embedding Shiny Apps for Interactive Data Analysis

Embedding Shiny Apps for Interactive Data Analysis

Shiny Apps are great tool for creating interactive R programs which can be embedded into any web page.

Depending on the app, it can be built as a dashboard for reporting and analysis, extracting data or even running fully fledged machine learning algorithms based on your requirements.

This example walks you through creating an interactive Leaflet Map, publishing it to a Shiny Server and embedding it in your website.
2022-04-08 18:40:54 UTC
Adding Multi-column Formats to R Markdown Documents

Adding Multi-column Formats to R Markdown Documents

It's possible to insert script tags inside raw HTML blocks and run your R code from there, but this is kind of nasty and takes the code out of the runnable framework, which is not a good idea where variables are being created/modified and used later on.

R Markdown supports some basic HTML elements. It also has its own notation for the <div> tag using the triple colon notation ::: for both opening and closing the element and, unlike using <div>, knitr won't auto-close these.

Learn how to use this and create a bootstrap responsive multi-column output directly from knitr.
2022-02-08 11:36:45 UTC
Better Looking Tables with kable in Your R Markdown Documents

Better Looking Tables with kable in Your R Markdown Documents

If you're using knitr with R markdown documents, you've probably come across the ubiquitous Xtable to display your dataframes and had to wrestle with either LaTeX or css to get the tables displaying with any sense of readability. The kable package comes with a lot of easy to use features including bootstrap styling to make life much easier.
2022-01-31 10:09:02 UTC
Use JavaScript to Add a Dynamic Table of Contents to Your Pages

Use JavaScript to Add a Dynamic Table of Contents to Your Pages

Creating a table of contents or menu based on content is time-consuming for editors and prone to errors. You may need such a feature on your data fed pages and not even have the ability to create and link to content on the page.

Here, I create an automated, on-the-fly table of contents without the need for hard-coded anchor links, regardless of the source of your content. It's easily adaptable to turn into a nav bar or similar menu. Similarly, this technique could be used to produce a summary with links on an API data feed page for rapid data analysis and drill-down capability.

At the end, I wrap it in a Wagtail stream block ready to drop into your templates.
2021-11-20 20:59:03 UTC
Translating Static Template Text with Wagtail Localize

Translating Static Template Text with Wagtail Localize

You have all your page content and snippet components translating successfully, but what to do with all those bits of static text in the non-Wagtail pages?

Static text lurks in the error pages, search results, e-mail templates and any Django pages that may be getting served on your site.

Here's an easy way to keep it all under the Wagtail Localize umbrella without the pain of making PO files and peppering your templates with blocktrans tags.
2021-11-07 14:08:18 UTC
Dealing with UNIQUE Fields on a Multi-lingual Site

Dealing with UNIQUE Fields on a Multi-lingual Site

In Django and Wagtail, for many translation models, a copy of the page tree is made for each language rather than inserting the translated text directly into the template or model.

This poses a problem for models that have fields with UNIQUE constraints as attempting to save a copy of the default language instance will trigger an integrity error (ie duplicate key).

Fortunately, if you're using the TranslatableMixin, there's a way around this.
2021-11-06 17:17:45 UTC
Configure Wagtail robots.txt and Block Search Indexing

Configure Wagtail robots.txt and Block Search Indexing

Rather than just being a static file, you can use Django/Wagtail templating to create a dynamically generated robots.txt. This is not the place to block search engine crawlers though, I'll show a method to apply that from your base template.
2021-09-12 18:03:07 UTC
Open Wagtail Rich Text Block Links in a New Tab

Open Wagtail Rich Text Block Links in a New Tab

You'd think this would be something you could do out of the box, but the makers of Wagtail have stated that this is against their philosophy and won't ever be implementing it. Here's a simple fix to circumvent that decision.
2021-09-09 11:59:19 UTC
Wagtail Introduction

Wagtail Introduction

Wagtail is a leading open source CMS utilising Python and the Django framework. Tens of thousands of organisations worldwide, including Google, Mozilla, NASA, and the British NHS are now using Wagtail. In case you're new to Wagtail, and looking to learn as a developer, I've gathered some great learning resources here to get you started.
2021-08-24 18:52:31 UTC