Firstly, the big question I was thinking a lot about this.
Since itβs brilliant single-threaded, itβs a bit complicated function to capture output and display it in brilliant form from what I know.
The work for this will be to use a non-blocking connection to the file and launch the function that you want to capture in the background while reading the file to display the function (check the history of changes to see how to do this).
Another way to do this would be to override the cat function to write to stderr (just switch cat with message ) and capture the output of the function as follows:
library(shiny) library(shinyjs) myPeriodicFunction <- function(){ for(i in 1:5){ msg <- paste(sprintf("Step %d done.... \n",i)) cat(msg) Sys.sleep(1) } } # Override cat function cat <- message runApp(shinyApp( ui = fluidPage( shinyjs::useShinyjs(), actionButton("btn","Click me"), textOutput("text") ), server = function(input,output, session) { observeEvent(input$btn, { withCallingHandlers({ shinyjs::text("text", "") myPeriodicFunction() }, message = function(m) { shinyjs::text(id = "text", text = m$message, add = FALSE) }) }) } ))
This example is mainly based on this daattali question.
Oskar forsmo
source share