我该如何捕获正在进行的
在使用
system()
操作的输出并将其实时流式传输到Shiny前端?intern=T
可以捕获整个输出为字符向量,但我更希望能够在系统输出发生时“监听”它。library(shiny)
ui <- fluidPage(
titlePanel("Stream the system output"),
sidebarLayout(
sidebarPanel(
actionButton("btn1",label = "Let's stream")
),
mainPanel(
textOutput("textstream_output")
)
)
)
server <- function(input, output, session) {
rv <- reactiveValues("textstream"=c(""))
output$textstream_output <- renderText({
rv$textstream
})
observeEvent(input$btn1,{
# problem: is evaluated after finish, not during operation
rv$textstream <- system("Rscript -e \"for(i in 1:5){ print(Sys.time()); Sys.sleep(1); };\"",
intern = T)
})
}
shinyApp(ui = ui, server = server)
在使用
intern=F
参数运行 system
命令时,R控制台每秒钟会持续更新。我该如何在Shiny中建立这个功能,最好不需要将 system
调用切分成较小的块?
可能相关: