Shiny: printing console output to a text object without waiting for a function to finish

前端 未结 1 1458
陌清茗
陌清茗 2020-12-14 10:58

I\'m new to Shiny and struggling considerably.

I need to give my Shiny users the ability to download a data file (essentially querying a database). The query goes fr

相关标签:
1条回答
  • 2020-12-14 11:39

    I think capture.output is good solution for capturing text from console.

     server <- function(input, output) {
      values <- reactiveValues()
    
      queryMagic <- function() {
        print("Warning")
    
        return("Data")
      }
      output$console <- renderPrint({
        logText()
        return(print(values[["log"]]))
        # You could also use grep("Warning", values[["log"]]) to get warning messages and use shinyBS package
        # to create alert message
      })
    
      logText <- reactive({
        values[["log"]] <- capture.output(data <- queryMagic())
    
    
      })
    }
    
    ui <- shinyUI(fluidPage(
      sidebarLayout(
        sidebarPanel(
        ),
        mainPanel(verbatimTextOutput("console"))
      )
    ))
    
    shinyApp(ui = ui, server = server)
    
    0 讨论(0)
提交回复
热议问题