如何通过 R 中的管道传递参数?
How to pass param through pipes in R?
我正在尝试通过管道传递参数,然后通过电子邮件发送数据。当我点击发送邮件按钮时,我的代码崩溃了。我不确定如何解决这个问题,因为我对 R 语言比较陌生。
library(shiny)
library(gmailr)
suppressPackageStartupMessages(library(gmailr))
library(shinyAce)
gm_auth_configure(path = "credentials.json")
ui <- fluidPage(
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(
textInput(inputId = "message", value="", label=""),
)))
server <- function(input, output, session) {
from <- reactive({input$from})
to <- reactive({input$to})
subject <- reactive({input$subject})
message <- reactive({input$message})
mail <- gm_mime() %>%
gm_from(from) %>%
gm_to(to) %>%
gm_subject(subject) %>%
gm_text_body(message)
observeEvent(input$send, {
gm_send_message(mail)
})
}
shinyApp(ui = ui, server = server)
这是我收到的警告错误。提前致谢。
Warning: Error in as.vector: cannot coerce type 'closure' to vector of type 'character'
87: as.character.default
85: gregexpr
84: substitute_regex
83: quoted_printable_encode
82: as.character.mime
80: lapply
75: as.character.mime
73: gm_send_message
72: observeEventHandler [C:/Users/Desktop/cred/sendemails.R#42]
1: runApp
这个有用吗?
ui <- fluidPage(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(textInput(
inputId = "message",
value = "",
label = ""
),)
))
server <- function(input, output, session) {
from <- reactive({
input$from
})
to <- reactive({
input$to
})
subject <- reactive({
input$subject
})
message <- reactive({
input$message
})
mail <- reactive({
gm_mime() %>%
gm_from(from()) %>%
gm_to(to()) %>%
gm_subject(subject()) %>%
gm_text_body(message())
})
observeEvent(input$send, {
gm_send_message(mail())
})
}
shinyApp(ui = ui, server = server)
我正在尝试通过管道传递参数,然后通过电子邮件发送数据。当我点击发送邮件按钮时,我的代码崩溃了。我不确定如何解决这个问题,因为我对 R 语言比较陌生。
library(shiny)
library(gmailr)
suppressPackageStartupMessages(library(gmailr))
library(shinyAce)
gm_auth_configure(path = "credentials.json")
ui <- fluidPage(
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(
textInput(inputId = "message", value="", label=""),
)))
server <- function(input, output, session) {
from <- reactive({input$from})
to <- reactive({input$to})
subject <- reactive({input$subject})
message <- reactive({input$message})
mail <- gm_mime() %>%
gm_from(from) %>%
gm_to(to) %>%
gm_subject(subject) %>%
gm_text_body(message)
observeEvent(input$send, {
gm_send_message(mail)
})
}
shinyApp(ui = ui, server = server)
这是我收到的警告错误。提前致谢。
Warning: Error in as.vector: cannot coerce type 'closure' to vector of type 'character'
87: as.character.default
85: gregexpr
84: substitute_regex
83: quoted_printable_encode
82: as.character.mime
80: lapply
75: as.character.mime
73: gm_send_message
72: observeEventHandler [C:/Users/Desktop/cred/sendemails.R#42]
1: runApp
这个有用吗?
ui <- fluidPage(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(textInput(
inputId = "message",
value = "",
label = ""
),)
))
server <- function(input, output, session) {
from <- reactive({
input$from
})
to <- reactive({
input$to
})
subject <- reactive({
input$subject
})
message <- reactive({
input$message
})
mail <- reactive({
gm_mime() %>%
gm_from(from()) %>%
gm_to(to()) %>%
gm_subject(subject()) %>%
gm_text_body(message())
})
observeEvent(input$send, {
gm_send_message(mail())
})
}
shinyApp(ui = ui, server = server)