R Shiny执行订单

gma*_*ais 6 r shiny

我对Shiny(和R)相当新,但我已经设法启动并运行了一个应用程序.

然而,我对RStudio实际运行两个脚本server.R和ui.R时发生的"执行顺序"感到很困惑.

在我看来,有4个代码段(2个用于server.R脚本,2个用于ui.R脚本):

server.R:

###### SECTION 1

shinyServer(function(input, output, session) {


  ###### SECTION 2


})
Run Code Online (Sandbox Code Playgroud)

ui.R:

###### SECTION 1

shinyUI(fluidPage(

  ###### SECTION 2

)
)
Run Code Online (Sandbox Code Playgroud)

我的问题是,假设我有上述正确,哪些部分是第一,第二,第三等?

Kot*_*ori 9

print在每个部分中添加语句并从RStudio运行.消息显示在控制台中.我有

[1] "section 1 of UI"
[1] "section 2 of UI"
[1] "section 1 of server"
[1] "section 2 of server"
Run Code Online (Sandbox Code Playgroud)

至于对象访问,我尝试了以下内容并查看每个环境中的变量.

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")
))
Run Code Online (Sandbox Code Playgroud)

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")
})
Run Code Online (Sandbox Code Playgroud)

我有:

[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 
Run Code Online (Sandbox Code Playgroud)