[![i=iris
library(shiny)
library(mailR)
ui =fluidPage(
fluidRow(
div(id = "login",
wellPanel(title = "Mail your report",
textInput("to", label = "To:", placeholder = "To:"),
textInput("sub","Subject:"),
textInput("msg","Message:"),
actionButton("mailButton",label = "Send mail")
)
),tableOutput(outputId = "fo")
)
)
server = function(input, output, session) {
observeEvent(input$mailButton,{
isolate({
send.mail(from = "*****@gmail.com",
to = unlist(strsplit(input$to, ";", fixed = TRUE)),
subject = input$sub,
body = input$msg,
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "****@gmail.com", passwd = "******", ssl = TRUE),
authenticate = TRUE,
attach.files = "fo",html = TRUE,
send = TRUE)
})
})
output$fo <- renderTable({
a<- as.data.frame(iris)
a$new <- a$Sepal.Length+a$Sepal.Width
a
})
}
runApp(list(ui=ui,server=server)) ][1]][1]
在这里,我们可以看到,在服务器功能中,我已经计算了一个新列,一个$ new,整个数据帧被保存回一个对象,所以我需要将这个数据帧作为pdf / csv / .html邮寄给任何可能的格式plz做这个指南
答案 0 :(得分:2)
i=iris
library(shiny)
library(mailR)
a<- as.data.frame(iris)
write.csv(a,file="test.csv")
ui =fluidPage(
fluidRow(
div(id = "login",
wellPanel(title = "Mail your report",
textInput("to", label = "To:", placeholder = "To:"),
textInput("sub","Subject:"),
textInput("msg","Message:"),
actionButton("mailButton",label = "Send mail")
)
),tableOutput(outputId = "fo")
)
)
server = function(input, output, session) {
observeEvent(input$mailButton,{
isolate({
send.mail(from = "****@gmail.com",
to = unlist(strsplit(input$to, ";", fixed = TRUE)),
subject = input$sub,
body = input$msg,
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "****@gmail.com", passwd = "nbwishes", ssl = TRUE),
authenticate = TRUE,
attach.files = "test1.csv",html = TRUE,
send = TRUE)
})
})
output$fo <- renderTable({
a<- as.data.frame(iris)
a$new <- a$Sepal.Length+a$Sepal.Width
write.csv(a,file="test1.csv")
})
}
runApp(list(ui=ui,server=server))