0

With reference to the code below, right now, all the verbatimTextOutput boxes are only updated when results have been returned for all the columns. I want the UI to show the output when results are returned for each column, to indicate that the application is indeed making progress. How can I do that?

INPUT_COL = c("V1","V2","V3")

shinyUI(fluidPage(
    sidebarLayout(
        sidebarPanel(
            uiOutput("controls")
        ),


        mainPanel(
          lapply(INPUT_COL, function(self){
            verbatimTextOutput(outputId=paste0("vb.",self))
          })
        )
      )
))


shinyServer(function(input, output,session) {
    output$controls<- renderUI({
        lapply(INPUT_COL, function(self) {
          output[[self]] <- renderUI(...)
          uiOutput(self)
        }) 
    })

    observe({
          params <- sapply(INPUT_COL, function(self) input[[self]])

          lapply(INPUT_COL, function(self) {
            output[[paste0("vb.",self)]] <- renderPrint(
              { tryCatch(
                {
                     results<- getResults(params) #some long process
                     print(results)
                },
                warning=function(war) return(war),
                error=function(err)  return(err) 
                )
              })
          })


      })

}
Jean
  • 1,480
  • 15
  • 27

1 Answers1

0

Figured it out by using a counter

status <-reactiveValues(i=0)

shinyServer(function(input, output,session) {
    output$controls<- renderUI({
        lapply(INPUT_COL, function(self) {
          output[[self]] <- renderUI(...)
          uiOutput(self)
        }) 
    })

    observe({
          params <- sapply(INPUT_COL, function(self) input[[self]])
          isolate({
            if (length(params) > 0){
              status$i <- status$i+1
              self <- INPUT_COL[status$i]
              output[[paste0("vb.",self)]] <- renderPrint(
                { tryCatch(
                  {
                       results<- getResults(params) #some long process
                       print(results)
                  },
                  warning=function(war) return(war),
                  error=function(err)  return(err) 
                  )
                })
            }  
          })

          if (isolate(status$i) < length(params)){ 
            invalidateLater(0, session) #reset the observer, so it'll repeat
          }
          else{
            isolate({status$i <- 0}) 
          }


      })

}
Jean
  • 1,480
  • 15
  • 27