Question

How do you add vertical gridlines between columns in the formattable R package?


Userlevel 4
Badge +1

I’m trying to make a copy of a visualisation of a table from Excel in R so that it can be automated as the original version is very labour intensive. From a google it seems formattable is the best package to achieve this, but I can’t find any documentation for adding lines between columns. 
Does anyone have experience with this package, and know how to do that?


5 replies

Userlevel 4
Badge +1

Hey! Not had much experience with the formattable package and similarly, I’m struggling to find documentation on adding column lines in. 

Have you tried using Kable extra package? Again, not something I’ve tried but there is a scope for automation (quick Google led to this), and there is an ability to add column lines in with something like…

kable() %>%
column_spec (1:7,border_left = T, border_right = T) %>%
kable_styling()

 

Userlevel 4
Badge +1

it seems formattable is the best package to achieve this, but I can’t find any documentation for adding lines between columns.

@BenLawson from what I can see in the formattable documentation and in online forums, there doesn’t seem to be the option of adding borders to columns. If the idea is to create a visual break between columns, then perhaps colouring the cells on one side of the border would create the desired effect? 

Alternatively, you can use the gt package. Its a very flexible package with a range of customisation options!

Userlevel 4
Badge +1

Have you tried using Kable extra package?

Hey Liz,
That was the first package I looked at, as it seemed to have some of the best documentation, but there’s other functionality it doesn’t have, such as conditional formatting!  

Userlevel 4
Badge +1

it seems formattable is the best package to achieve this, but I can’t find any documentation for adding lines between columns.


Alternatively, you can use the gt package. Its a very flexible package with a range of customisation options!

Yeah GT is what i’m going to go with, it seems to have all the good things about formattable, but with more options as well! Cheers Wes 

Userlevel 3
Badge +1

Hi Ben, 

If you’re making a html table, the DT package allows gridlines with class = "cell-border and conditional formatting with formatStyle. However, it's not very good if you want to export the table as a pdf.

 

Reply