繁体   English   中英

闪亮的仪表板中的进度条

[英]Progress bar in shiny dashboard

我正在开发一个闪亮的仪表板,用户可以在其中发送电子邮件。 一旦他点击Send Email按钮,我想显示用户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函数将电子邮件发送给所需的收件人。 我应该在哪里放置进度条代码,以便在电子邮件发送开始后立即启动。

我希望这可以帮助你...

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.'))


}) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM