从闪亮的发送电子邮件

时间:2013-12-31 12:00:10

标签: r shiny

我是一个新的Shiny用户,我有兴趣创建一个网络应用程序,访问者可以填写一些问题(取决于随机R数据),他们可以提交。

我的问题是找到通过电子邮件向我发送信息的方式,例如,每次提交数据时。

我是一名大学讲师,我认为这是评估学生的好方法。

3 个答案:

答案 0 :(得分:6)

以下是我在Shiny应用中测试sendmailR包时编写的Shiny电子邮件发件人。在Linux平台上,我没有配置任何东西,应用程序完美无缺。用户在由shinyAce包生成和处理的文本区域中键入消息正文。

<强> ui.R

shinyUI(pageWithSidebar(

  headerPanel("Email sender"),

  sidebarPanel(
    textInput("from", "From:", value="from@gmail.com"),
    textInput("to", "To:", value="to@gmail.com"),
    textInput("subject", "Subject:", value=""),
    actionButton("send", "Send mail")
  ),

  mainPanel(    
    aceEditor("message", value="write message here")
  )

))

<强> server.R

library(shinyAce)
library(sendmailR)

shinyServer(function(input, output, session) {

  observe({
    if(is.null(input$send) || input$send==0) return(NULL)
    from <- isolate(input$from)
    to <- isolate(input$to)
    subject <- isolate(input$subject)
    msg <- isolate(input$message)
    sendmail(from, to, subject, msg)
  })

})

答案 1 :(得分:1)

R绝对可以发送电子邮件。通过Google搜索R send email会将我引导至sendmailR包,该包可从CRAN获得。另请查看:

答案 2 :(得分:0)

这应该是一个好的开始:

library(shiny)
ui <- pageWithSidebar(
  headerPanel("fill this and send"),
  sidebarPanel(

  ),
  mainPanel(
    textInput("name", "Name:", ""),
    textInput("body", "Body:", ""),
    actionButton("goButton",label = "Send this")

  )
)


server <- function(input, output) {
  observe({
    # Take a dependency on input$goButton
    if (input$goButton == 0)
      return(NULL)
    # Use isolate() to avoid dependency on input$goButton
    isolate({
      info <- data.frame(subject=paste("New info from:",input$name),
                         body = info$body)
      InfromMe(info)
    })
  })
}
runApp(list(ui=ui,server=server))

其中inforMe是使用PaulHimstra回答的邮件功能:

#####send plain email
InfromMe <- function(info){
  from <- "you@account.com"
  to <- "recipient@account.com"
  subject <- info$subject
  body <- info$body                    
  mailControl=list(smtpServer="serverinfo")
  sendmail(from=from,to=to,subject=subject,msg=body,control=mailControl)
}