gpt4 book ai didi

R Shiny 执行命令

转载 作者:行者123 更新时间:2023-12-04 11:41:55 27 4
gpt4 key购买 nike

我对 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com