簡體   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