2016-11-25 167 views
1
[![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] 

這裏附加一個數據幀作爲PDF/html的,因爲我們可以看到,在服務器功能我已經計算出一個新的列$新的,完整的數據幀保存回一個對象,所以我需要郵寄這個數據幀爲PDF/CSV/html的任何可能的格式PLZ做指導這個發送電子郵件問題::從Shinyapps.io

+0

你應該張貼的代碼作爲文本,以便其他用戶可以對代碼進行測試。 –

+0

@JakeConway你是什麼意思的文字。該代碼已經在這種形式只有 – Veerendra

+0

@Veerendra沒有問題先生我已經上傳了代碼,幸運的是我也得到了解決方案也.so謝謝你的評論 –

回答

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)) 
+0

這是解決方案,完全正常工作!只要確保你在工作的目錄! –