Building A Web Page with R

Building A Webpage with R

This post aims at providing a step-by-step process of building a site using R blogdown package. The blogdown package’s objective is to provide a strong and customisable R Markdown output. The package makes use of Hugo, a well-known open-source static website generator, to provide a simple and adaptable way to build your site content for online publishing.

Why to have a blog? This is a question worth to ponder. I think best answer is given by David Robinson, in a podcast, hosted by Hugo Bowne Anderson. According to David, a blog is a critical tool always advised, if you are, or willing to be, a data scientist as it helps you keep track of what you’ve thought and done. There are several sources to digest blogdown package. Firt and foremost, the book written by Yihui Xie, Amber Thomas, Alison Presmanes Hill is probably the best and well known source. There are also several blogs. Nonetheless, it is a demanding task.

To assist you, this post will give a brief and straightforward tutorial on how to create a blog from scratch. Lets begin with the requirementys:

Once, you have done these, just follow up the steps below (in order):

Step 1: Creating a GitHub repository

To create Github repository is the first step. The best documentation is available through the official GitHub webpage. However, I strongly recommend additional one in-depth course and one book, some of which are given below:

Step 2: Creating a project with Git in RStudio

3. Create website with {blogdown}

library(blogdown)
new_site(theme = "wowchemy/starter-academic") # you can pick different themese from https://themes.gohugo.io

⚠️ Type y in your Console.

4. Step 4: Push ⬆︎ to GitHub

At this point, it is better to have base files on the Github repositories up and running.

4.3 Check files

Another tto do is to check the local files and see missings. The pieces of code below will render the result from where you can easily spot problems (TODOs!).

# checks to resolve critical [TODOs] before commit
blogdown::check_site()

5 Deploy site with Netlify

  • Select New site from Git > Continuous Deployment: GitHub
  • Select your website repository
  • Deploy Site
  • Settings > Site information > Change site name

6 Custumize the site

At this point, you should custumize the site as your wishes. To do that, find the relevant content and edit the idex files. If you willing to create new post to your site, the code below would be enough in creating it.

creting posts

blogdown::new_post(
  title = "wep-page-with-R",
  ext = '.Rmarkdown',
  subdir = "post"
)

Of course, you can edit the post anytime!

# to edit the post
rstudioapi::navigateToFile("content/post/2022-06-19-wep-page-with-r/index.Rmarkdown")
Hakan Mehmetcik
Hakan Mehmetcik
Assoc. Professor

My research interests include social data science with a speciality of International relations