Of course, but I wonder if creating the reactiveFileReader directly inside renderPrint is erroneous. Here is a (somewhat lengthy) chunk of code where it does not work whereas using a reactive variable does.
library(shiny)
library(processx)
asyncUI <- function(id) {
ns <- NS(id)
tagList(
fluidRow(
actionButton(ns("runProc"), "Sleep"),
verbatimTextOutput(ns("logf")),
),
)
}
asyncServer <- function(id, logFile)
moduleServer(id, function(input, output, session) {
mainProcess <<- NULL
observeEvent(input$runProc, {
mainProcess <<- process$new("count.tcsh")
})
procTimer <- reactivePoll(1000, NULL,
checkFunc = function() {
if(is.null(mainProcess))
NULL
else
mainProcess$is_alive()
},
valueFunc = function() {
if(is.null(mainProcess))
NULL
else
mainProcess$is_alive()
})
# logTimer <- reactiveFileReader(intervalMillis = 500, session=NULL, filePath = logFile, readFunc = readLines)
output$logf <- renderPrint({
req(!is.null(procTimer()))
reactiveFileReader(intervalMillis = 500, session=NULL, filePath = logFile, readFunc = readLines)()
#logTimer()
})
})
ui <- fluidPage(
asyncUI("myrun"),
)
server <- function(input, output, session) {
asyncServer("myrun", logFile="count.log")
}
shinyApp(ui, server)
This runs a script count.tcsh
that writes to a file counts.log
. It displays the log in real time. count.tcsh script is
#!/bin/tcsh
echo "Begin script" >! count.log
foreach i (`seq 1 10`)
sleep 1
echo $i seconds passed >> count.log
end
echo Finished script >> count.log
When I run it (in Linux), the version above does not display all the log file counts from 1 to 10, but (for a reason unknown to me) stops at count 2-3. If I use a variable inside renderPrint, it works just fine.