How to renderPlot only after the observeEvent produces reactiveValues, not before

Hello!
In my Shiny app, the user hits an action button (input$run) and that initiates the following section on server side:

main_reactive <- reactiveValues() 
observeEvent(input$run, {
 ...
  a lot of different calculations ...
 main_reactive$forplot = mydataframe
})

Once the calculations in this observeEvent are finished, I'd like to generate a plot:

output$my_plot <- renderPlot({  use the output main_reactive$forplot  })

However, Shiny attempts to build a plot immediately. Even if I start inside renderPlot with this:

   output$my_plot<- renderPlot({
     if (input$run == 0) return(NULL)
     input$run
     isolate(print(ggplot(...))

It's still not working - because until my observeEvent is finished calculating, there is nothing for the renderPlot to use. How could I make renderPlot wait for the results of my observeEvent - until my reactive values are available?

Thank you very much!

1 Like

Or should I just move my renderPlot inside my observeEvent?

Hi! I don't know if you've tried using req(input$run) instead of the if statement?
http://shiny.rstudio.com/reference/shiny/latest/req.html

req() worked for me with a file upload input and a DT table output :slight_smile:

Edit: I think you can actually use req(main_reactive$forplot)..

1 Like

8 posts were split to a new topic: renderPlot loops continuously with req()