Shiny doesn't expect to click bar to render chart

Hi,

Welcome to the RStudio community!

The easiest way of executing code only under certain conditions is by wrapping it in an observeEvent statement like this:

library(shiny)

ui <- fluidPage(
  actionButton("myButton", "Click me"),
  plotOutput("myPlot")
)

server <- function(input, output, session){
  
  data(iris)
  
  observeEvent(input$myButton, {
    
    output$myPlot = renderPlot({
      plot(iris)
    })
    
  })

}

shinyApp(ui = ui, server = server)

The plot will only be created once the button is clicked and the observeEvent activated.
More details on the function can be read here: observeEvent

By the way, in future I encourage you to create a reprex when you have a question where you provide us with minimal code and data to recreate the issue so it's easier for all to understand and help you out. You can find details on creating one here:

Hope this helps,
PJ