It looks as though the css associated with the table classes is not shipped in the email (this would be table, table-striped, table-hover, etc.). There's probably a way embed the kable css in the table output (maybe inline styling), but it could get messy. Alternatively, you define your own styles by taking the kable output and putting it up a html "document". Here's an example
- Generate html table
# get html output
table <- knitr::kable(iris, "html")
- we will define the css.
# css
css <- '<style type="text/css">
table {
border-spacing: 0;
cursor: default;
}
table tr * {
padding: 7px;
}
table > thead > tr > th {
border-bottom: 3px solid #525252;
text-transform: lowercase;
}
table > thead > tr > th {
font-size: 14pt;
font-weight: 400;
font-family: "Helvetica", sans-serif;
}
table > tbody > tr:nth-child(odd) {
background-color: #f1f1f1;
}
table > tbody > tr > * {
font-family: "Lucida Console";
font-size: 11pt;
}
table > tbody > tr:hover {
background-color: #FFD670
}
</style>'
- format as an html document
# paste as html document
email <- paste0("<!DOCTYPE html><html><head>",
css,
"</head><body><div>",
"<h1>Check out this table!</h1>",
table,
"</div></body></html>")
- assemble the draft and send the email.
# build draft
html_msg <- mime() %>%
to("...your email here...") %>%
from("...your email here...") %>%
html_body(email)
# send
html_msg %>%
subject("Example Table") %>%
send_message()
This generates the following output.
Hope that helps! There's probably a better way to incorporate the kable output formatting, but this might give you an idea on how to structure the content.