admin管理员组

文章数量:1399466

I've built an Rmarkdown document which includes some ggplot visualizations as well as some buttons to download the data supporting the visualizations. These buttons were built using the download_this package.

I've rendered the Rmd to html and have then used compose_email to generate the content for the email.

When I view the email object (blastula_message email_message) everything looks great in the Viewer window in Rstudio, the buttons work, I can download the data as well as the images in jpeg format.

When I then use smtp_send, using the correct email server details the email sends however when it lands into my inbox the buttons are stripped out, only the text for the buttons remains

Any suggestions for why this may be happening would be greatly appreciated

        ---  
title: "Analysis of the mtcars Dataset"  
author: "Your Name"  
date: "`r Sys.Date()`"  
output: html_document  
---  
  
```{r setup, include=FALSE}  
knitr::opts_chunk$set(echo = TRUE)  
```

Introduction
 
The mtcars dataset is a built-in dataset in R that contains data about different car models. It includes 32 observations with 11 variables, such as miles per gallon (mpg), horsepower (hp), weight (wt), and more.

In this report, we will:

Summarize the dataset
Calculate some basic statistics
Visualize relationships between key variables
Dataset Overview
 


# Display the first few rows of the dataset  
```{r}
head(mtcars) 
```

Summary Statistics
 
Here, we calculate summary statistics for the numerical variables in the dataset.


# Summary statistics  
```{r}
summary(mtcars) 
```

 
 

Visualization
 
Well create a scatter plot to explore the relationship between weight (wt) and miles per gallon (mpg).

```{r}
library(ggplot2)
```

  
# Scatter plot of weight vs. mpg  

```{r}
ggplot(mtcars, aes(x = wt, y = mpg)) +  
  geom_point(color = "blue", size = 3) +  
  labs(title = "Scatter Plot of Weight vs. Miles Per Gallon",  
       x = "Weight (1000 lbs)",  
       y = "Miles Per Gallon (mpg)") +  
  theme_minimal() 
```

```{r}
# Save mtcars dataset as an Excel file  
temp <- mtcars 
  
# Add a download button using downloadthis  
downloadthis::download_this(  
  .data = temp,  
  output_name = "mtcars_dataset",  
  output_extension = ".xlsx",  
  button_label = "Download mtcars Dataset as Excel File",  
  button_type = "success"
)
```


Conclusion
 
This report provides a basic overview of the mtcars dataset. We observed some interesting relationships, such as the negative correlation between weight and miles per gallon. Further analysis could include more advanced statistical modeling or exploring other variables in the dataset.


```

Here is my code to send the email

# LOAD THE LIBRARY
library(blastula)

# RENDER THE HTML DOCUMENT FROM Rmarkdown
rmarkdown::render("C:/myEmail.Rmd", output_format = "html_document", output_file = "mtcars_file.html")

# READ THE HTML FILE CONTENT
mtcars_html_content <- paste(readLines("mtcars_file.html"), collapse = "\n")

# COMPOSE THE EMAIL
mtcars_email <- compose_email(
  body = md(mtcars_html_content),
  content_width = "1800px"
)

mtcars_email

# SEND THE EMAIL
mtcars_email %>% 
  smtp_send(
    from = "[email protected]",
    to = "[email protected]",  
    subject = paste0("MTCARS - ", Sys.Date()),
    credentials = creds_key("outlook")
  ) 

本文标签: rIssues with sending blastula emails with buttons in the email contentStack Overflow