2016-11-22 4 views
0

Mit Bezug auf den Code unten, gerade jetzt, werden alle VerbatimTextOutput-Felder nur aktualisiert, wenn results für alle Spalten zurückgegeben wurden. Ich möchte die Benutzeroberfläche die Ausgabe zeigen, wenn results für jede Spalte zurückgegeben werden, um anzuzeigen, dass die Anwendung tatsächlich Fortschritte macht. Wie kann ich das tun?Aktualisieren glänzende Ausgabe innerhalb der Schleife

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) 
       ) 
       }) 
      }) 


     }) 

} 

Antwort

0

es herausgefunden, indem unter Verwendung eines Zählers

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}) 
      } 


     }) 

} 
Verwandte Themen