我正在开发一个闪亮的仪表板,用户可以在其中发送电子邮件。点击Send Email
按钮后,我想显示用户发送电子邮件的进度。目前我正在使用以下代码,首先执行进度条,然后开始发送电子邮件。
observeEvent(input$send_email, {
final_data <- loadData()
city <- input$city_select
country <- input$country_select
email_type <- input$email_select
start_date <- format(input$dateRange[1])
end_date <- format(input$dateRange[2])
from <- as.integer(input$from)
to <- as.integer(input$to)
progress <- Progress$new(session, min=1, max=15)
on.exit(progress$close())
progress$set(message = 'Sending Emails',
detail = 'This may take a while...')
for (i in 1:to) {
progress$set(value = i)
Sys.sleep(0.5)
}
email_data <- final_data[final_data$registrant_city == city & (final_data$create_date >= start_date & final_data$create_date <= end_date),]
emails<- quick_email(email_data,city,country)
emails <- emails[from:to]
send_email(emails,input$subject_select)
session$sendCustomMessage(type = 'testmessage',
message = paste0('Emails have been successfully sent to ',city,' region,please update the excel sheet.'))
})
send_email
功能将电子邮件发送给所需的收件人。我应该在哪里放置进度条代码,以便在电子邮件发送开始后立即启动。
答案 0 :(得分:0)
希望这对您有帮助...
observeEvent(input$send_email, {
req(input$email_select) # you dont want to send with out selecting any emails
final_data <- loadData()
city <- input$city_select
country <- input$country_select
email_type <- input$email_select
start_date <- format(input$dateRange[1])
end_date <- format(input$dateRange[2])
from <- as.integer(input$from)
to <- as.integer(input$to)
# I would prefer the withProgress
withProgress(value = 0,message = 'Sending Emails',
detail = 'This may take a while...'{
email_data <- final_data[final_data$registrant_city == city & (final_data$create_date >= start_date & final_data$create_date <= end_date),]
incProgress(amount = .2, message = "Add you message or ignore") #Add you message or ignore
emails<- quick_email(email_data,city,country)
incProgress(amount = .4, message = "Add you message or ignore") #Add you message or ignore
emails <- emails[from:to]
incProgress(amount = .7, message = "Almost done") #Add you message or ignore
send_email(emails,input$subject_select)
incProgress(amount = 1, message = "Done Here") #Add you message or ignore
})
session$sendCustomMessage(type = 'testmessage',
message = paste0('Emails have been successfully sent to ',city,' region,please update the excel sheet.'))
})