rstudio / blastula

Easily send great-looking HTML email messages from R
https://pkgs.rstudio.com/blastula
Other
548 stars 85 forks source link

Make add_image/ggplot responsive in Outlook #304

Open caldwellst opened 1 year ago

caldwellst commented 1 year ago

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.