R Shiny 执行命令

标签 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


})

ui.R:
###### SECTION 1

shinyUI(fluidPage(

  ###### SECTION 2

)
)

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

最佳答案

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

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

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

用户界面
VarDefinedInSec1UI <- 1

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

shinyUI(fluidPage(
  VarDefinedInSec2UI <- 2,

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

服务器
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 

关于R Shiny 执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35039736/

相关文章:

r - 计算给定其他列数据的概率

R - 如何获得两点之间耗时?

r - 在 Shiny 的应用程序中抑制阴谋警告

R Shiny (选择输入): object "choices" not found

r - 如何使用Shiny中的下载按钮?

r - 如何通过输入键在 Shiny 中加入两个 react 数据帧?

R:测试函数从封闭环境中获取哪些对象

r - 用于 glm.fit 的 predict() 不起作用。为什么?

r - 如何根据用户输入打印不同的数据框? Rmarkdown/ Shiny

r - 防止 selectInput 包装文本