Table Column spacing in R tableHTML and mailr

1.4k Views Asked by At

I am trying to send a mail via mailr and it working fine. For sending a small table of 5 lines - I am using HTML format and it is working fine too.

I am using htmlTable package - the only disadvantage as of now is that I am not able to control the width of the column or the gap between the columns. Is there a possible way to control this.

I tried the kable and kableExtra package but the output is coming without any css formatting - a very plan HTML, however the Viewer in Rstudio is showing great but mail comes in without any formatting.

Even tried the formattable, it ok to somextent, but some CSS lookwise are getting removed in mailr - but is working for me, but lacks column size control here too.

Please advice on how to add column gaps/widths in htmlPackage or get the desired html formatting in mail using kable/kableExtra. or any knowledge sharing would be appreciated too.

1

There are 1 best solutions below

8
On BEST ANSWER

You can use tableHTML for this (which is the package you tagged!!). As a small example, the argument widths controls the widths of the columns:

library(tableHTML)
mtcars[1:4, 1:5] %>%
  tableHTML(widths = rep(100, 6))

enter image description here

You can pretty much add any kind of (other) CSS you want into the table by using the add_css_column function for columns (or any other add_css_ function for other parts of the table). There is a detailed explanation on the vignette.