Display Pretty R tables in GitHub

Display Pretty R tables in GitHub

One thing I love about performing analysis in .Rmd (R Markdown) files is how easy it is to share your results publicly on GitHub. Create your analysis in the .Rmd file, set your output variant as below, knit to .md format and then add your files to GitHub!

 
md.png
 

The Difficulty In Displaying Pretty R Tables In .md

There is only one problem with the .md output: PRETTY TABLES! Most of the pretty tables packages that I like to use don’t display all of the formatting, or don’t display at all in .md format.

The Solution

Fear not, this is very easily solved by simply changing your output to html and setting up GitHub pages on your GitHub repo.

The Example

Step 1: Create your .Rmd files with your pretty tables and set the output to html_document as per below.

The example full .Rmd file can be found here. The final webpage with pretty R tables can be found here.

 
html.png
 

Step 2: Knit to HTML

This is a pretty easy task. Simply hit the “Knit” button in the top menu within RStudio. See the video below for a demo.

 
 

Step 3: Create a Repo and add your .Rmd and .html files

Next, create a GitHub repo and add your html file. Follow the steps below or watch the demo for instructions.

  • Create a new GitHub repo

  • Go to the “Code” area > click “Add file”

  • Add “index.html” and “index.Rmd” file from the above step

 
 

Step 4: Publish your HTML as a GitHub Page

Next, enable GitHub pages on your repo and gather your new page link. Follow the steps below or watch the demo for instructions.

  • Navigate to the repo > “Settings” > Scroll to “GitHub Pages”

  • Select a branch. If you are unsure, just select “Main” and “Save”.

  • Select a theme. I selected “Minimal”. If you need to save the new README.md file for this, please do so.

  • Navigate back to “Settings” > Scroll to “GitHub Pages”. Your URL should now be displayed. It will display text similar to: “Your site is published at {URL}”

  • Celebrate because your beautiful data tables are now displayed in GitHub!

 
 

Optional: Change your `README.md` file to link to your html page

You may want to change your README.md file to direct your readers to your html page. Simply edit the README and add a link to the GitHub pages URL.

 

THANK YOU

Thank you for reading about how to host your pretty R tables in GitHub. Please remember that the full .Rmd file can be found here. The final webpage with pretty R tables can be found here.

Please reach out to me on twitter to let me know if you like the package and share your findings.

 
Conference: Black In Data Week

Conference: Black In Data Week

Create Easy US Maps in R - Thanksgiving Edition

Create Easy US Maps in R - Thanksgiving Edition