blastula icon indicating copy to clipboard operation
blastula copied to clipboard

Can't add header and footer in the .Rmd file which I use to render a blastula email

Open Dante-Guerrero opened this issue 3 years ago • 4 comments

You can add a header and a footer with compose_email, but I can't do that with de .Rmd document I use with render_email. Does somebody know how to do that? @rich-iannone

Dante-Guerrero avatar Aug 20 '20 04:08 Dante-Guerrero

It's possible but, during my testing, it's not really obvious how to do this (but the method I'll show here seems to work). Try this: create an Rmd file and use the blastula::blastula_email output format. Here's an example:

---
title: "Test"
output: blastula::blastula_email
---

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

Then create a script that uses the .Rmd file in a compose_email() call. I'm using images in the blastula package to create the header and the footer (with add_image()):

library(blastula)

logo_header <-
  add_image(
    system.file("social_icons", "github-color.png", package = "blastula"),
    width = 100
  )

logo_footer <-
  add_image(
    system.file("social_icons", "github-light_gray.png", package = "blastula"),
    width = 30
  )

compose_email(
  header = logo_header,
  body = render_email("document.Rmd")$html_html,
  footer = logo_footer
)

What you should see in the preview is:

rmd-header-footer-preview

Which should be sendable without issues at this point. Try this out and let me know if it works for you.

Note to Rich and @jcheng5: using render_email("document.Rmd") in the body argument did not work.

rich-iannone avatar Aug 20 '20 04:08 rich-iannone

Sorry @rich-iannone, I try to send an email with gmail and this happened: imagen As you can see, there is a frame (maybe beacuse of the render_email template). It doesn't appear in RStudio viewer, just when you send it.

Dante-Guerrero avatar Aug 20 '20 17:08 Dante-Guerrero

I also try with the full ".Rmd" file and it look like this: imagen

Dante-Guerrero avatar Aug 20 '20 17:08 Dante-Guerrero

@cderv gave some insights at https://community.rstudio.com/t/blastula-insert-footer-into-email/86421/2 (adding link to the footer in the yaml, and producing the footer.html via a chunk)

I think it is a bit more elegant, as you can add specific, computed information in the footer. Is there a disadvantage?

To get to use mardown and specific input, I think one needs to use a R chunk like

{r, echo= FALSE}
x=markdown::markdownToHTML(text=blastula::md("Do not hesitate to contact [me](mailto:[email protected]) if you have wishes, questions and/or feedback."), fragment.only = TRUE)

write(x, file ="footer.html")


jcolomb avatar Sep 20 '21 10:09 jcolomb