0

我有一个功能可能需要超过 10 分钟,并且想将一些进度信息动态输出到 UI。我编写了一个测试脚本,它使用闪亮网站中的演示作为参考,但它不起作用。

服务器.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);
    }
  }
})

用户界面

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")
    ))
  )
))

期待您的帮助,谢谢。

4

0 回答 0