Blinging up your website built with hugo via blogdown R package

Having a presence on the internet is becoming increasingly important for gaining exposure. In particular, having a personal website that shows your skill can help build your reputation and form your personal brand.

The purpose of this blog post is to show the use of simple but cool html tricks to embed within your website and building your own showcase website.

You will need to have R and Rstudio installed. You should be familiar with some basic programming. It will be helpful to know html, css, and javascript but I didn’t know much when I started so it shouldn’t be a barrier to learn.

Quick website set up using blogdown

My aim here is not to give you a comprehensive introduction to blogdown but just so you can get started. For a detailed introduction, I would refer you to the blogdown book. If you find some issues, the author, Yihui Xie, prefers you write the problem on stack overflow with the tag blogdown instead of submitting it to github issues.

First install the blogdown package if you haven’t got it:


Next go to the directory that you plan to create a folder with all the files related to your website by using setwd(path/to/your/directory) or otherwise. Then run the following command to create a new site in folder yoursite using the Hugo Introduction theme by Vicki Lai.

blogdown::new_site(dir="yoursite", install_hugo=TRUE, theme="hivickylai/hugo-theme-introduction")

You can do the same using the File > New Project > New Directory > Website using blogdown.

You can easily change the theme BUT first delete the folder that was created.

The list of hugo theme can be found here. To use the hugo themes that are hosted in github, you need to know the github username and repository and replace theme=username/repository in the argument. The github page can be usually found from selecting one of the theme here > Homepage. The username and repositary can be found in the url in the form of

After you have chosen the theme that you want, the first thing is to open the file config.toml. Usually it’s pretty straight forward here. Replace the values in the config.toml to your details. After you have done that run the command


You should find the site is now rendered on the Viewer pane in RStudio.

Getting an error running the above command? You may be able to fix this by updating blogdown to the latest version. blogdown has dependencies so you those may need to update those too so try running the following if it’s still not working for you:


If you are still having an issue then try googling it first. If you really have trouble resolving it then post the error message in stack overflow with the blogdown tag. If you can, put a minimum replicable example with your post.

Why blogdown instead of hugo alone?

You may have been able to tell but the website is in fact created by hugo and blogdown acts as a wrapper in R for hugo. So what’s the point of blogdown? Why not just work with hugo alone?

What makes blogdown amazing is its ability for a seamless workflow of creating a website with sections rendered by R markdown.

This is probably explained best by an example. Let’s say we make our first post.

blogdown::new_post(title="Hello World!", slug="firstpost", subdir="blog")

This should make a new markdown document that will load in RStudio. Here is a glimpse of what I wrote in that markdown: Now if you run blogdown::serve_site() (or if you still have it running from before, it may automatically update as you change it), you should be able to see your post. The address of the post should be something like your.base.url/blog/firstpost. You will then see something like below image So the above just shows the R commands but did not evaluate those commands. Let’s redo this with R markdown. You can do this by adding by the argument ext=".Rmd" as below.

blogdown::new_post(title="Hello World!", slug="firstpost", subdir="blog", ext=".Rmd")

Since it is a R markdown, you need R to execute the R commands. So now running blogdown::serve_site(), we have: and you can see that the plot has rendered!

This whole process streamlined makes posts with R commands easier and also makes it easily reproducible!

For comparison, I used to have to run R markdown separately, copy the generated html content in the appropriate place in my website. It was not a simple copy and paste too as websites usually come with its own preambles and footer. If there were images that were rendered then I have to move the figures in the corresponding place for the images to render in the webpage. Needless to say, the whole process was cumbersome. And before R markdown, it was even more work. I can’t emphasise enough how great blogdown has made it for blogging!

How do you deploy your website?

The easiest option is use netlify. I set up my one via github pages. You can find more details here.

Code syntax highlighting

Some hugo websites come with built-in syntax highlighting.

Be aware that the Viewer pane in RStudio sometimes does not show the syntax highlighting but it will show in the website if you open it up via other browser. This took me a while to realise.

For a more detailed description about syntax highlighting, check out Amber Thomas’ blog post.

Using hugo short code in R markdown

Some hugo themes will come with its own hugo shortcodes. These can be quite handy but if you are using R markdown, it doesn’t work as it does in markdown. E.g. I can embed a tweet by using

{{< tweet 989847683295686656 >}}

in the markdown but to make it work in R markdown, you need to use

htmltools::HTML("{{< tweet 989847683295686656 >}}")

Blinging up your website with html tricks

These tricks are more likely to break your website so be sure to back it up before attempting them. It is better to attempt these higher level customisation once you can deploy your website with the standard customisation that comes with the hugo theme.

Once you realise the structure of how hugo generates the website then you can start to see how to embed some custom html codes to bling up your website. For example, here is a glowing twitter icon:

To place this in your website, go first to this website then on the footer and click on the Export then Unzip this file.

This parcticular so-called pen comprises of html and css. Copy the css folder from the pen folder into the static folder in your website folder.

Next open the index.html from the pen folder using RStudio (or a text editor of your choice). For this part, you need to have a read through of the code to find the relevant part. You cannot simply copy and paste all the content of index.html since your website will have it’s own header, body structure and footer. Scanning index.html, the relevant code for the pen is contained here

  <div class="wrapper">
  <svg width="200" height="200" viewBox="0 0 216 216">
    <path id="twitter" d="M193.9,64c0.1,1.9,0.1,3.8,0.1,5.7c0,58.6-44.6,126.1-126.1,126.1c-25,0-48.3-7.3-67.9-19.9

      stroke-dasharray="1100 1100"

This code only draw the outline of the twitter icon. The glow and outline animation are coded within the css files. You need to link to those files that you copied to the static folder before within the post and this can be done by placing below in your post.

<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/css/7534eb3fb62294822de9eace9.css">

You can search other pens at codepen. It’s a bit tricky to get it right and more than often I break my website or it overwrites the css where I don’t want it to.

You probably want to think the purpose of whatever code you want to insert on your website. Having too much bling can make the website “heavy” and may distract away from the content of your website. It’s also an investment of your time to implement right and it just might not be worth it. Nonetheless, it’s a chance to do a higher level customisation. I tweaked the Academic theme to get those effects on my main website. I recently came across Earo Wang’s webpage and I can see she tweaked the Academic theme too. She’s using tufte-like format and it looks fantastic! I updated my footer after seeing hers. Anyhow proceed with some caution but have fun blinging up your website!

Making a showcase website

What is a showcase website?

I designed my showcase website specifically to graphically showcase my results from my selected work and collboarations. It’s a concept more popular with artists but I thought why not with statistics or data science? It’s a great way to communicate what your skills are and from the popularity of my tweet, the idea seems to have resonated well with the community.

My showcase website got Hadley Wickham’s endorsement as a fantastic way to show off a portfolio of your work when you are looking for a data science job.

I would love to see more of these showcase websites. If you make one, I would love to see it. You may like to use the hashtag


to share your showcase website so everyone can easily see your website, get inspired, you can get a feedback on it or you may even get a job offer from it. You learn a lot from others’ creative works. I find that I’m constantly inspired by others - particularly from Sarah Romanes! (Sarah’s got style! She’s to watch out for!).

You can see my showcase website here. This was made by using the Forty theme. I did very little customisation for this theme so it will be easy for you to implement it as well. So give it a try and I hope I get to see your showcase!

comments powered by Disqus