Creating a website using Rblogdown
I have used R blogdown package to setup this static website. Thanks to Yihui Xie, Amber Thomas, and Alison Presmanes Hill for their hard work. First, I have started reading their E book to understand the basics. Then, I have setup a simple website by using the default theme (hugo-lithium
) as suggested by the authors. Next, I have changed the theme to hugo-academic. However, for this website I have used the Mainroad theme. In this post, I will explain the steps that you have to follow to create a static blog.
1. Open RStudio, and install blogdown package and Hugo
install.packages("blogdown")
blogdown::install_hugo()
The blogdown package, acts as an interface between R and Hugo, which is a generator for static web pages.
2. Create a New Project using the New Directory option.
Select File
-> New Project
-> New Directory
-> Website using blogdown
Then fill the dialog box, and create the website. Use the default Hugo theme
when you start creating a website first. Later you can change this theme.
3. Check and update your project options by selecting Tools -> Project Options.
(i) First check Build tools option. Your project type should be Website
(ii) Yihui suggests to uncheck the following options
• “Preview site after building” ,
• “Re-knit current preview when supporting files change” : this option is not really useful after you call serve_site().
(iii) Then check Git/SVN option, and set the Version control system to Git.
4. Build the website by clicking Build Website
Use the code blogdown::build_site()
Then, to preview your website locally click Addins
, and select Serve site
.
Now, the website will be compiled, and the local server will activate. You can view the website in the Viewer panel. The Addins command blogdown::serve_site()
will continuously serve your website locally using the LiveReload technology. You can edit material for the website while you are previewing it.
5. Do changes in the configuration file config.toml according to your choice.
For example, you can change the title of you website. For more details regarding the config.toml refer https://bookdown.org/yihui/blogdown/
.
6. Create a GitHub remote repository, and upload the required files
Except public folder, .Rproj, READMe.md
, and .gitignore
files, upload other files to the GitHub remote repository.
7. Deploy the Website To host the Website, you can select from free providers such as as Netlify or GitHub Pages. To use Netlify
- Register at Netlify
- Associate Netlify with the website’s GitHub repository
- Netlify will automatically build and deploy your Website every time you do any change in the GitHub repository
Further details: - blogdown tutorial by Peter Baumgartner
- blogdown tutorial by L.collado