我有一个功能可能需要超过10分钟,并希望动态输出一些进度信息到UI。我写了一个测试脚本,它使用闪亮的网站中的演示作为参考,但它不起作用。
Server.R
shinyServer(function(input, output, session) {
logfilename<-"logfile.txt"
MyFunc(logfilename)
session$onSessionEnded(function() {
unlink(logfilename)
})
fileReaderData <- reactiveFileReader(500, session,logfilename, readLines)
output$fileReaderText <- renderText({
text <- fileReaderData()
length(text) <- 10
text[is.na(text)] <- ""
paste(text, collapse = '\n')
})
MyFunc<-function(logfile){
for(i in 1:20){
Sys.sleep(10);
cat(i, '\n', file = logfile,append = TRUE);
}
}
})
UI.R
shinyUI(fluidPage(
titlePanel("reactivePoll and reactiveFileReader"),
fluidRow(
column(12, p("The log file is appended to every second."))
),
fluidRow(
column(6, wellPanel(
"This uses a reactiveFileReader, which is monitoring the",
"log file for changes every 0.5 seconds.",
verbatimTextOutput("fileReaderText")
))
)
))
期待你的帮助,谢谢。