0

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.

surpavan
  • 1,372
  • 7
  • 34
  • 66

1 Answers1

2

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.

LyzandeR
  • 37,047
  • 12
  • 77
  • 87
  • Thank you, I was waiting eagerly for this. Not sure why the package PDF does not say anything on css and widths this way :(. You saved me a lot on it. – surpavan Mar 23 '18 at 17:17
  • You are very welcome. That was our main motivation to make this package. CSS is crucial in HTML tables :) – LyzandeR Mar 23 '18 at 17:28
  • I initially solved this with writing a fuction to replace the first '>' with colgroup tag with given text. Not a clean method but gave a temporary solution. But thank to you, I now have a good & correct solution. – surpavan Mar 23 '18 at 18:40
  • I am not sure what you are talking about. Is this a new question? – LyzandeR Mar 26 '18 at 08:02
  • Sorry, I corrected my comments - I miss took the package as htmltable instead of tablehtml - both have similar names. Solved. Thank you. – surpavan Mar 26 '18 at 08:43
  • I tried the code of widths - it is working in browser - but not working in outlook mail as col is not supported in outlookmail – surpavan Mar 26 '18 at 09:21
  • If outlook does not support HTML / CSS then not much can be done with HTML packages... – LyzandeR Mar 26 '18 at 09:29
  • But thank you, I am using add_css_column to get what I want - this way it is working. the width parameter in tablehtml is not supported, but CSS is working. Thank you once again. – surpavan Mar 27 '18 at 05:30