How should one think of the order of non-reactive shiny server commands?

In the Mastering Shiny book it is said that

It’s important to understand that the order your code run is solely determined by the reactive graph. This is different from most R code where the execution order is determined by the order of lines.

So why does the following Shiny app


ui <- fluidPage(

server <- function(input, output, session) {

shinyApp(ui, server)

output to the console first 1 and then 2 ?
And why does it output these values only once, and not an infinite number of times?

Your code doesnt define any reactive objects nor link them in a reactive graph.
The Mastering Shiny book is really excellent in my opinion.

Right, I should have asked more precisely - how should one think of the order of non-reactive shiny server commands ? Are they run in sequence? Only once?

P.s. Now updated in the title and added "non-reactive"

yes, they run in sequence like an r script, the server code is run line by line.
any reactive code in there can contribute to setting up the reactive graph, and non reactive code just runs when its encountered.

However, in a module, if the last statement is a return statement, it does not get executed immediately, in the sense that the module does not finish the execution when the return statement is evaluated.

a module is reactive code and so lazy and would only be evaluated if some other reactive element needed it to paint , or was forced like an observe

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.