Is it possible to send visualizations through RDCOM?

点点圈 提交于 2019-12-10 10:37:39

问题


I am relatively new to R programming and have undertaken a little side project to introduce myself to the world of R. What I would like to do is help one of my colleagues automate a manual email process that he does each week.

The email consists of a chart created in excel, DOW index prices, our company's stock prices, and some commentary that he manually updates each week.

I have figured out how to use the RDCOMClient package to send emails but what I would like to do is integrate into the body of the email (in HTML format if possible) the charts and stock prices that he also pulls. I am hoping to automate all of this so all he has to do is update commentary and run the script.

The key limiting factor here is the target audience, this will be going out to executives who really do not like having to open email attachments. They want to open an email on their phone, get the relevant information, and move on.

This is what my program looks like so far:

library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = "test@test.com"
outMail[["subject"]] = "R Test"
outMail[["body"]] = "Hello"                   
outMail$Send()

回答1:


Sure, first you save your image. Then use HTMLbody to insert the image using HTML code as follows:

library(htmlTable)

png("pictest.png")
plot(iris$Sepal.Length)
dev.off()

StockPrice <- "25.25"

MyHTML <- paste0("<html><p>This is a picture.</p> 
<img src='C:/Users/iwes/Desktop/RWorkingFolder/pictest.png' >
<p> Our StockPrices is: $", StockPrice,
"<p>here is a table:</p>",
htmlTable(head(iris,5)))

library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = "test@test.com"
outMail[["subject"]] = "R Test"
outMail[["HTMLbody"]] =  MyHTML                  
outMail$Send()


来源:https://stackoverflow.com/questions/44162385/is-it-possible-to-send-visualizations-through-rdcom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!