gccd
gccd

Reputation: 49

How to control the order of execution of the program in Shiny

I have noticed that the GUI components of my APP try to display all at the same time and if the display is slow (my computer only has two processors), they display at the same time and out of order. I wonder if there is a way to control the order of display of the GUI components and if some widget is slow displaying, make the other widget displays wait until the previous has completed. Additionally, I found that in my 2 processors computer, if a function takes an enormous amount of time, any other previous GUI component does not display and the long function seems to take over the processor. I do not know very much about this, but is if all the functions were being loaded at the same and competing for the resources. Is there any way to control the order of execution of the program? Thanks.

Upvotes: 1

Views: 433

Answers (1)

divibisan
divibisan

Reputation: 12155

The best way I've come up with to enforce a (rough) order of execution is liberal use of the req function. From ?req:

Ensure that values are available ("truthy"–see Details) before proceeding with a calculation or action. If any of the given values is not truthy, the operation is stopped by raising a "silent" exception (not logged by Shiny, nor displayed in the Shiny app's UI)

You could use req to require that the first widget has completed (either by checking it's expected output, or by using a variable as a first_widget_done flag) before proceeding with the second widget's code.

RE: Truthy:

The terms "truthy" and "falsy" generally indicate whether a value, when coerced to a logical, is TRUE or FALSE.

as.logical(0)   # FALSE
as.logical(1)   # TRUE

Upvotes: 1

Related Questions