I am currently developing an user interface based on R markdown and shiny to make it easy to execute a machine learning training process for other users not proficient in R. This training process is done by a custom built function around the R package mxnet and gives status updates like the training error or what packages are loaded with the message()
function directly to the console, when run in a "normal" R script. However, when running this app in R markdown nothing is printed to the browser. The following script shows a minimal reproducible example (with the training process replaced with an easy "dummy" function):
---
title: "Training of a Neural Network"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r start_training, echo=F}
inputPanel(
actionButton("button_start_training", "Start training")
)
```
```{r dummy_function, echo=F}
dummy_function <- function(){
for(i in 1:5){
message(paste0("Test: "),i)
Sys.sleep(0.5)
}
}
```
```{r actual_training, echo=F}
event_training = eventReactive(input$button_start_training,{
dummy_function()
})
renderPrint({
event_training()
})
```
The console output from dummy_function()
is not displayed in the browser, but only in the console. If message()
is replaced by print()
something is displayed in the result, but only after the function is completed and not "live". Because the actual training process takes a few hours, I would like to give these updates as they would occur in the console. Furthermore, replacing message()
by print()
could cause some issues since things like the training error are returned inside the mxnet training process as a message and not as a print (if I understood it correctly).
So, this boils down to two questions:
- Is there a way to make
renderPrint()
print output as soons as it appears? - Is there a way to make
renderPrint()
use output generated bymessage()
instead ofprint()
?
Thank you for your help.