【问题标题】:Progress bar in shiny dashboard闪亮仪表板中的进度条
【发布时间】:2016-11-11 13:20:08
【问题描述】:

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

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    希望对你有所帮助...

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

    【讨论】:

      猜你喜欢
      • 2015-04-22
      • 1970-01-01
      • 2019-07-26
      • 1970-01-01
      • 1970-01-01
      • 2019-02-12
      • 2019-06-20
      • 2020-06-10
      • 2016-05-02
      相关资源
      最近更新 更多