rstudio / blastula

Easily send great-looking HTML email messages from R

Home Page:https://pkgs.rstudio.com/blastula

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make add_image/ggplot responsive in Outlook

caldwellst opened this issue · comments

Outlook does not typically support max-width and responsive design. However, there is a workaround highlighted in this SO post. My current email tasks are almost entirely going to Outlook users, and I wanted to use blastula::add_image() and blastula::add_ggplot(), but the output is not ideal for Outlook (on Windows machines in particular).

However, with a simple wrapper on the end of those functions, I stripped out the HTML output and replaced it with the solution that allows for responsive image viewing in Outlook for Windows. I essentially convert:

<table width="100%" align="center">
  <tr>
    <td>
      <img src="image-path" alt="" width="520" style="width:520px;"/>
    </td>
  </tr>
</table>

into:

<table border="0" cellspacing="0" width="100%">
  <tr>
    <td></td>
    <td width="520">
      <img src="image-path" alt="" width="520" style="display:block;width:100%"/>
    </td>
    <td></td>
  </tr>
</table>

You essentially vary the alignment by leaving out cells. While it's a bit hacky, I believe it's a very valuable solution to have for emails with significant numbers of recipients using Outlook.

Could this be added to blastula itself? It could be an additional parameter to add_image() and add_ggplot() to return this, or a separate function entirely? If agreed, happy to help implement in the source code.