2
在我的Shiny頁面上,有一個步驟用於讀取大型日誌文件,該文件需要25s才能加載。我想在用戶點擊一個按鈕後顯示一個進度條。否則,他們可能會認爲它在等待時不工作。R Shiny放置在哪裏withProgress
#ui.R
#I have an actionButton to activate reading the log file
actionButton("getLog","Get Log data")
#server.R
observeEvent(input$getLog, {
nL = as.numeric(countLines("/script/cronlog.log"))
Log = read.table("/script/cronlog.log",sep = ";",skip = nL-1000)
LogFile = tail(Log,100)
colnames(LogFile) = "cronlog"
})
我正在嘗試使用withProgress,但我不知道如何使用它來包裝代碼。我想是這樣的:
observeEvent(input$getLog, {
withProgress(message = 'Calculation in progress',
detail = 'This may take a while...', value = 0, {
for (i in 1:60) {
incProgress(1/60)
Sys.sleep(0.25)
}
})
nL = as.numeric(countLines("/script/cronlog.log"))
Log = read.table("/script/cronlog.log",sep = ";",skip = nL-1000)
LogFile = tail(Log,100)
colnames(LogFile) = "cronlog"
})
進度條沒有出現,但它似乎是加載進度的進度條,這使得該方法甚至更長的時間之後運行。我想我沒有正確包裝代碼。
有什麼建議嗎?
預先感謝您!