Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different rendering behaviour in Microsoft Outlook and mobile Email App #540

Closed
leungi opened this issue Apr 10, 2020 · 2 comments · Fixed by #1114
Closed

Different rendering behaviour in Microsoft Outlook and mobile Email App #540

leungi opened this issue Apr 10, 2020 · 2 comments · Fixed by #1114
Assignees
Milestone

Comments

@leungi
Copy link

leungi commented Apr 10, 2020

As per subject; screenshots attached.

Mobile (as expected)

mobile-email

Microsoft Outlook (style stripped)

outlook-email

Reprex

library(gt)
#> Warning: package 'gt' was built under R version 3.6.3
library(dplyr)
#> Warning: package 'dplyr' was built under R version 3.6.3
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

df <- tibble(`Non Risky` = c(9, 12, 21), `Risky` = c(1, 0, 1)) %>%
  mutate(
    Total = `Non Risky` + Risky,
    `At Risk Percentage` = Risky / Total
  )

df %>%
  gt() %>%
  tab_style(
    style = cell_text(
      color = "white"
    ),
    locations = cells_column_labels(
      columns = everything()
    )
  ) %>%
  tab_options(
    row.striping.include_table_body = FALSE,
    column_labels.font.weight = "bold",
    column_labels.background.color = "black"
  ) %>%
  fmt_percent(vars(`At Risk Percentage`), decimals = 1) %>%
  data_color(
    columns = vars(Risky),
    colors = scales::col_bin(
      c("red", "green"),
      bins = 2,
      domain = c(0, 100)
    ),
    alpha = 0.8
  )

Package version

> packageVersion("gt")
[1] ‘0.2.0.5

Created on 2020-04-10 by the reprex package (v0.3.0)

@rich-iannone
Copy link
Member

Try using the as_raw_html() function at the end of the gt() call before embedding the table into the email message body. The reason that works is because email clients will sometimes strip out CSS rules but if the CSS styles are inlined into the HTML tags, then you'll see tables with all formatting preserved in pretty much all email clients.

You could also expand your reprex a bit to show us how you're generating the email message.

@leungi
Copy link
Author

leungi commented Apr 16, 2020

@rich-iannone : thanks for prompt reply.

I did try the as_raw_html() as well, and the result was slightly better - header column retains CSS styling, but body still got stripped (refer to below).

image

Email is generated via mailR, as follow:

library(mailR)

from <- "from@gmail.com"
to <- "to@gmail.com"
subject <- "Test"

body <- glue::glue("{gt_tbl_as_html}")

send.mail(
    from = from,
    to = to,
    subject = subject,
    body = body,
    encoding = "utf-8",
    smtp =
      list(host.name = <host_name>, port = 25, ssl = FALSE),
    authenticate = FALSE,
    send = TRUE,
    html = TRUE,
    inline = TRUE
  )

@rich-iannone rich-iannone added this to the FUTURE milestone Aug 22, 2022
@rich-iannone rich-iannone modified the milestones: FUTURE, v0.8.0 Nov 10, 2022
@rich-iannone rich-iannone moved this from Backlog to Todo In Progress in R Markdown Team Projects Nov 10, 2022
Repository owner moved this from Todo In Progress to Done in R Markdown Team Projects Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants