2016-11-25 9 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/csv/.html形式で郵送する必要があります。Rshinyでメールを送信::データフレームをShinyapps.ioからpdf/.htmlに添付する

+0

他のユーザーがコードをテストできるように、コードをテキストとして投稿する必要があります。 –

+0

@JakeConwayテキストをどういう意味ですか?コードはすでにフォームに入っています – Veerendra

+0

@Veerendra問題はありません。私はすでにコードをアップロードしています。幸いにも私も解決策を得ました。コメントありがとうございました –

答えて

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

これは完全に解決策です。ちょうどあなたが働いているディレクトリを確認してください! –

関連する問題