Skip to content

Creating beautiful, interactive, simple and elegant data tables using kable in R

Use-case: I wanted to create a report on a data using r markdown, and my next goal was providing simple and interactive data table for summary stats or contextual information around data. Hence, I came accross this R package, called kable. In this example and tutorial, I provide a ready to execute and step by step code tutorial on how to apply this table package on data and then learn to customize the output and code for your own need.

My goal is to create a legend table for identifiers on a categorical variable. I create a unique id or identifier for this column, a categorical or string column, and then visualize this kind of table at the end:

output table of this tutorial example

A video tutorial, complementing this blog is available from here:


Step1: initial settings and packages installation & loading

Step2: data preparation for table: creating unique id for column in dataframe / R

Step3: kable code snippet

table %>% kbl(caption = “Legend IDs for Sectors”) %>% kable_classic(full_width = F, html_font = “Cambria”) %>% kable_styling(bootstrap_options = c(“striped”, “hover”, “condensed”), full_width = F, position = “float_right”)

Related links:

  • code solution as r script:( this file format is txt. change the format to Rmd to open it as a r markdown file.)
  • data sample:

Leave a Reply

Your email address will not be published. Required fields are marked *