関数に 10 分以上かかる場合があり、進行状況の情報を UI に動的に出力したいと考えています。光沢のある Web サイトのデモを参考にしてテスト スクリプトを作成しましたが、動作しません。
サーバー.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")
))
)
))
よろしくお願いします。