我是一个新的闪亮用户,我有兴趣创建一个web应用程序,访问者可以填写一些问题(取决于随机R数据),他们可以提交他们。
我的问题是找到通过电子邮件向我发送信息的方法,例如,每次他们提交数据时。
我是一名大学讲师,我认为这是评估我的学生的一个好方法。
发布于 2013-12-31 21:26:04
这是我写的一个闪亮的电子邮件发送器,用来在一个闪亮的应用中测试sendmailR
包。在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")
)
))
。R 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)
})
})
发布于 2013-12-31 12:18:35
R绝对可以发送电子邮件。在谷歌上搜索R send email
可以找到sendmailR
包,它可以从CRAN获得。还可以查看以下内容:
发布于 2013-12-31 13:17:19
这应该是一个很好的开始:
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 answer的邮件函数:
#####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)
}
https://stackoverflow.com/questions/20857068
复制