RStudio for building a blog/website? My tips

![Author: Daniel Thomas Source: Unsplash](cover image.jpg)

Do you know you can build and manage a website using RStudio? Just over a week ago I did not know either! But when I learnt about it during one of my (random) R-related DuckDuckGoing sessions^[Yes, I am currently not using Google Search as my main search engine], I knew I had to give it a go. My website is still unfinished but you can have a look at it to understand what you can do in under 2 days (or faster if you follow my tips r emo::ji("point_down")).

My current homepage

So, how do you build a website using RStudio? With blogdown, Hugo, GitHub, and Netlify!

Blogdown is a package that helps you to generate webpages from R Markdown documents. This means, for instance, that you can display chunks of R code (and its outputs). This can be a real life saver for a blog post where you talk about code. I think a good example is Claus’ blog post on performing PCA using tidyverse. Important note - he used blogdown r emo::ji('wink').

![Official blogdown book](blogdown image.png){width=35%}

But blogdown on its own is not enough, we need a static site generator on which blogdown can be based. The official blogdown book recommends using Hugo.

GitHub will be used to store your code which will be accessed by Netlify so your blog/website can be deployed.

Now you know the core components of building a blog/website using RStudio, but how to get it running?

Just a quick note before we move. In this blog post I do not intend to provide you with a comprehensive guide on building your own blog/website. There are plenty of amazing resources and to some of them I link at the end of this blog post. Rather, the goal is to introduce you to the idea of using RStudio for building and managing your blog/website and share some tips + a modified workflow for building a site using blogdown.

Setting and running a website

There are many great resources that will help you start. I began by reading and following the bookdown book from cover to cover^[OK, except for appendices].

Everything was going well until I had to deploy my website. I was not sure what it wanted from me, so I started searching for a gap in my understanding and went back to page one. My attention was captured by a note from the authors where they linked to a blog post by Alison (one of the book’s co-authors). Long story short, I wasted a lot of time because I believed that GitHub cannot be that hard to use, hence, I did not read Happy Git and GitHub for the useR when it was recommended by Alison. Indeed, many of the tutorials on setting a blog/website using blogdown will assume the minimal level of GitHub knowledge and familiarity with RStudio.

Hence, my very first advice before you start building a blog/website would be to sort your Git and GitHub!

I followed Happy Git and GitHub for the useR. It was easy to follow and I encountered no issues whatsoever. If you have never heard about GitHub, you might find chapter 3 of the Introduction to Computational and Data Sciences useful^[Also, getting familiar with Git and GitHub might make it easier to transition to data science career where you might have to collaborate with others on various projects].

Once you have your Git and GitHub working and connected to RStudio, you can proceed to building your blog/website by following the blogdown book or Alison’s blog post. I followed Alison’s blog post and installed Hugo Academic theme because the designed suited me.

Here comes my second tip: do not to invest too much time and energy into choosing the right first theme.

I have a couple of reasons behind this. First, you do not know if you will like using RStudio to build and manage your blog/website. Indeed, other website builders might suit your needs better (but more on this later). So, try to get an idea of what it means to use blogdown and Hugo before you decide to customize your blog/website^[This applies even more so if you are thinking of migrating your current blog/website]. Second, most probably you (just like me) have little idea of what and/or why is happening. I was happy it worked^[After I managed to connect Git and GitHub to RStudio]. After the initial burst of joy, I started reading the wowchemy documentation to customize my theme. It is not that simple! Indeed, the theme of my choice - Hugo Academic - has a lot of extra widgets which I had to hide (and understand how to hide!), so next time I would go for a much simpler theme. I would say that in the beginning it is better to start small and add extra sections/pages as you understand the functioning of Hugo and blogdown better. However, if you do decide to choose a theme that has many widgets, have a look if it is accompanied with a detailed and easy-to-follow documentation that would help you to customize the theme.

So far I have provided two tips that I wish I had followed to make my first encounter with blogdown smoother. However, I acknowledge that the entire workflow can still be hard to grasp.

So here is my modified workflow:

  1. Create a GitHub account, connect Git and GitHub to your RStudio
  2. Create a new repository (project) in GitHub, copy its URL and paste it when you start a new project on RStudio
    • do not worry, all of this will be explained in Happy Git and GitHub for the useR
  3. Create a website
    • install blogdown package
      • for this, complete section 1.1
    • FUN TIME: pick a theme
      • completing section 1.2 should give you a sense of how it is done
      • alternatively you can follow Alison’s blog post
      • I also recommend choosing a simple one. A default hugo-lithium theme looks like one r emo::ji ("slightly_smiling_face")
      • there are enough guides/tutorials on setting up your blog/website with blogdown, so explore what others suggest too
  4. Deploy your website
    • I am using Netlify as it seems to be recommended but others also use GitHub Pages
    • Netlify seems pretty straightforward for me but you can still have a look at this step-by-step guide detailing the steps that need to be taken to deploy your site
    • final result should look something like in the image below (but it will depend on your theme)

![Representation of my website using Hugo Academic on Netlify](Hugo Academic.png)

  1. Edit your website
    • add/delete pages
    • add blog posts!
    • check if your website gets updated when you edit the code/files in the repository (do not forget to commit as Netlify is linked to your GitHub!)
      • if there are problems, double-check previous steps
      • currently my website on Netlify looks like in the image below

![Current representation of my website on Netlify](My homepage on Netlify.png)

  1. Enjoy!

Some final notes

Hopefully, you have now (a vague) idea of how you can use RStudio to build your blog/website that supports R Markdown documents. Yet, I still want to say that there are other site builders that might work better for your needs. If you do not see yourself ever needing the R Markdown support on your blog/website, then maybe other website builders could work better for you, such as [Wix.com](https://www.wix.com/. In my opinion^[It is not based on a lot of experience] to take advantage of the blogdown, you do need to have a need to publish R Markdown as a webpage. Therefore, you will have to learn R Markdown. While it is not hard, it will take time and practice, so you have to take into consideration this as well.

Time is a factor to consider. For me, it took less 2 days to set up my very basic website. Hopefully you will save some time by following the workflow I laid out earlier. However, it is also important to note that I have had some experience in building a website on WordPress, which means that I had already known what my current needs are before I started building a website using blogdown. Also, while I am still learning R (will I ever stop learning it?!), I am not a total novice. If you have just started learning R, you might be better off with another site builder.

Indeed, you might not even need a personal blog/website! We have DataQuest Direct where we can post blog posts for others to read. Actually, posting them here might reach a wider audience than if you posted it on your personal blog. The reason I want to have a personal blog is pretty simple - I like having an online space which is for me and about me. Let me know in the comments what are your reasons behind (not) wanting a personal blog/website!

Useful resources

Key blogdown resources to consult:

Git + GitHub:

  • Bryan and Hester’s Happy Git and GitHub for the useR
    • David’s blog post provides a very comprehensive guide (with videos!) on getting everything set up based on the Bryan and Hester’s book
  • chapter 3 from Glasbrenner, Kulkarni, and White’s Introduction to Computational and Data Sciences
  • GitHub Guides

R Markdown:

Some other cool resources I came across:

One realy last point: when you search for resources to build/customize a website with blogdown, pay attention to when it was published as some of it might be outdated.

If you have any questions, do not hesitate to get in touch! You can do so by leaving a comment r emo::ji("point_down") or simply connect via LinkedIn.

3 Likes

Hey @gretatimaite. Awesome article.

Thank you Michael! :slight_smile: