R Brilliant execution order

I am new to Shiny (and R for that matter), but I managed to run the application and run it.

I, however, was rather confused about the "execution order" that occurs when RStudio actually runs two scripts server.R and ui.R

In my opinion, there are 4 sections of code (2 for server.R script and 2 for ui.R script):

server.R:

###### SECTION 1

shinyServer(function(input, output, session) {


  ###### SECTION 2


})

ui.R:

###### SECTION 1

shinyUI(fluidPage(

  ###### SECTION 2

)
)

My question is that I correctly formulated which sections are launched first, second, third, etc.

+4
source share
1 answer

print RStudio. .

[1] "section 1 of UI"
[1] "section 2 of UI"
[1] "section 1 of server"
[1] "section 2 of server"

, .

ui.R

VarDefinedInSec1UI <- 1

print("* section 1 of UI")
cat(ls(), "\n\n")

shinyUI(fluidPage(
  VarDefinedInSec2UI <- 2,

  print("* section 2 of UI"),
  cat(ls(), "\n\n")
))

server.R

VarDefinedInSec1Server <- 3

print("* section 1 of server")
cat(ls(), "\n\n")

shinyServer(function(input, output, session) {
  VarDefinedInSec2Server <- 4

  print("* section 2 of server")
  cat(ls(), "\n\n")
})

:

[1] "* section 1 of UI"
VarDefinedInSec1UI 

[1] "* section 2 of UI"
VarDefinedInSec1UI VarDefinedInSec2UI 

[1] "* section 1 of server"
VarDefinedInSec1Server 

[1] "* section 2 of server"
input output session VarDefinedInSec2Server 
+7

Source: https://habr.com/ru/post/1626196/


All Articles