Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shiny 如何使反应式函数成为全局函数?_Shiny_Rstudio - Fatal编程技术网

Shiny 如何使反应式函数成为全局函数?

Shiny 如何使反应式函数成为全局函数?,shiny,rstudio,Shiny,Rstudio,在下面的代码中,我如何在otherfunction()中使用myData()对象,这是为在服务器函数中实现而编写的另一个函数。现在myData()是本地的吗?我怎样才能使它全球化 library(shiny) write.csv(data.frame(a = 1:10, b = letters[1:10]), 'test.csv') runApp(list(ui = fluidPage( titlePanel("Uploading Files"), sidebarLayout( sidebarP

在下面的代码中,我如何在otherfunction()中使用myData()对象,这是为在服务器函数中实现而编写的另一个函数。现在myData()是本地的吗?我怎样才能使它全球化

library(shiny)
write.csv(data.frame(a = 1:10, b = letters[1:10]), 'test.csv')
runApp(list(ui = fluidPage(
titlePanel("Uploading Files"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv'))
),
mainPanel(
tableOutput('contents')
)
)
)
, 
shinyServer (function(input, output, session){
myData <- reactive({
inFile <- input$file1
if (is.null(inFile)) return(NULL)
data <- read.csv(inFile$datapath, header = TRUE)
data
})
output$contents <- renderTable({
myData()
})

theotherfunction=theotherfunction(input,output,session)

}
)
)
)
库(闪亮)
write.csv(data.frame(a=1:10,b=letters[1:10]),'test.csv')
runApp(列表(ui=fluidPage(
titlePanel(“上传文件”),
侧边栏布局(
侧栏面板(
fileInput('file1','选择CSV文件',
接受=c('text/csv',
'文本/逗号分隔值,文本/普通',
“.csv”)
),
主面板(
tableOutput('内容')
)
)
)
, 
shinyServer(功能(输入、输出、会话){

myData另一个函数
与服务器函数有何不同?您为什么需要它?反应式函数确实有一个作用域,您可以通过指定
env=parent.frame()重新定义它
子句。但我不想这么做!更简单的是,你可以使用
反应性值
而不是
反应性值
。你可以在代码的任何部分定义和引用
反应性值
,因为它只是一个返回用于存储反应性值的对象的
函数。