【发布时间】:2016-02-11 17:59:23
【问题描述】:
在我的 Shiny 页面上,有一个读取大日志文件的步骤,需要 25 秒才能加载。我想在用户单击按钮后显示进度条。否则他们可能会在等待时认为它不起作用。
#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"
})
进度条确实出现了,但加载进度似乎在进度条之后运行,这使得过程更长。我想我没有正确包装代码。
有什么建议吗?
提前谢谢你!
【问题讨论】:
标签: r shiny shinydashboard