How can I set up triggers or execution order for eventReactive or ObserveEvent?

I need to save changes to numeric data.frame, then have every other react in my group's dashboard trigger and execute in a particular order. This way the user see the changes they have inputted into the algorithm. How can I control the execution and trigger order of our react variables?
Are there any experts in shiny that are willing to help?

The Details:
I was able to finally deploy my shiny app: https://mlane6.shinyapps.io/unitedway/
Below is the code to my algorithm (the link).


Because I know its a bit complicated, I tried to produce a diagram by hand to show how I have connected everything:
https://www.draw.io/#G1XJn_U5G6c9YiyZ5YBij7AAzGugfBE4hq

As the diagram shows, a slider called metric is created when the user changes variables. The algorithm uses data from original constraints. This metric slider triggers all of the other reacts in the script. One particular even reactive called myupdate stores the replaces the values in original constraints with the values of metric slider. Then other reacts are supposed to compute based on those changed values.

However, click on other inputs in the dashboard something about the execution order causes the data in original constraints to reset.

I think the solution might be saved to disk then have the other variables access it through disk. The documentation talks about such a method here https://shiny.rstudio.com/articles/persistent-data-storage.html. However, I really would like to control the execution order in order to simplify the dashboard for the user.

Can anyone help?

(P.S. If there is a debug command so I can show how the reactive work which each other please let me know)

When I have a reactive that I don't want to run until another reactive has completed, I trigger the 2nd reactive with a reactive variable that I increment at the end of the first reactive's code.

Something like:

rv <- reactiveValues()
rv$run2 <- 0

observeEvent(whateverTrigger, { 
   whateverCode
   rv$run2 <- rv$run2 + 1
})

observeEvent(rv$run2, {
   whateverCode
})

While in the simple case shown here you could just combine these into a single observeEvent, there are more complicated cases where this helps to reuse your code.

Tom

2 Likes