condition panel on completion of a loop

Hi All,

How can I have a conditionalpanel that only displays after a loop is completed. My actually, app runs a simulation which involves a loop and takes a while, and then makes some graphs. For a minimum working example, I have altered one of the instructional apps. Imagine the loop rather than the trivial one actually created the data to be graphed. In other words, at the end of the loop, in the example below, t equals 20, but the graph is not displayed; how can I get the graph to be displayed but only after the loop?

Thank,
Dustin

library(shiny)

# Define UI for app that draws a histogram ----
ui <- fluidPage(
  
  # App title ----
  titlePanel("Hello Shiny!"),
  
  # Sidebar layout with input and output definitions ----
  sidebarLayout(
    
    # Sidebar panel for inputs ----
    sidebarPanel(
      
      checkboxInput("Graphs", "Graphs", value = FALSE),
      
      # Input: Slider for the number of bins ----
      sliderInput(inputId = "bins",
                  label = "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30),
      
      actionButton("go", "Submit")
      
    ),
    
    # Main panel for displaying outputs ----
    mainPanel(
      
      conditionalPanel(
        condition = "input.go && observeEvent(output.t==20)",
      # Output: Histogram ----
      plotOutput(outputId = "distPlot")
      )
    )
  )
)

# Define server logic required to draw a histogram ----
server <- function(input, output, session) {
  
  # Histogram of the Old Faithful Geyser Data ----
  # with requested number of bins
  # This expression that generates a histogram is wrapped in a call
  # to renderPlot to indicate that:
  #
  # 1. It is "reactive" and therefore should be automatically
  #    re-executed when inputs (input$bins) change
  # 2. Its output type is a plot
  
  observeEvent(input$go, {
    for (i in 1:20) {
      print(i)
    }
    
    output$t <- renderText(i)

    output$distPlot <- renderPlot({
    
      x    <- faithful$waiting
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    
    hist(x, breaks = bins, col = "#75AADB", border = "white",
         xlab = "Waiting time to next eruption (in mins)",
         main = "Histogram of waiting times")
    })
  })
  
  
}

shinyApp(ui = ui, server = server)

You need to start by editing your post to make it possible for people to actually copy and paste the code — it looks like you have forgotten to surround it in code markers (```). I'd then recommend reading the advice in https://mastering-shiny.org/action-workflow.html#making-a-minimal-reprex about how to reduce your reprex to the smallest possible case.

I'm confused by the logic of your request, it seems to me if you simply left out the conditional panel, there wouldnt be an output$distPlot function until your 20 loops, so your graph would be blank and not display until the desired time already without adding an extra conditional panel layer.

Hadley,
Thanks, that worked!
-Dustin