问题描述
我部署了一个使用约 700Mb 的 .Rdata 文件的 Shinyapp。
Rdata 文件加载到 server-inputdata.R
文件中,server.R
文件如下所示:
options(shiny.maxRequestSize = 100*1024^2)
source("helpers.R")
print(sessionInfo())
shinyServer(function(input,output,session) {
source("server-inputdata.R",local = TRUE)
source("server2.R",local = TRUE)
source("server3.R",local = TRUE)
})
此处,server2.R
和 server3.R
具有使用从 server-inputdata.R
中的 .Rdata 文件加载的数据的可视化代码
无论何时加载应用程序,都会为每个用户加载 Rdata 文件。有人可以帮助如何仅加载一次数据并为用户提供即时访问。在 https://stackoverflow.com/questions/31557428/r-load-only-once-a-rdata-in-a-deployed-shinyapp
处检查了一个类似的线程,它没有帮助解决我的问题。
这是server-inputdata.R
中的代码
inputDataReactive <- reactive({
load('04.Rdata')
return(list("data"=data_results,"data_results_table"=data_results_table))
print("uploaded data")
})
解决方法
尝试将源代码行:source("server-inputdata.R",local = TRUE)
放在服务器函数之外,例如:
options(shiny.maxRequestSize = 100*1024^2)
source("helpers.R")
source("server-inputdata.R",local = TRUE) # loaded once per session
print(sessionInfo())
shinyServer(function(input,output,session) {
source("server2.R",local = TRUE)
source("server3.R",local = TRUE)
})
,
移除反应式函数就成功了。
options(shiny.maxRequestSize = 100*1024^2)
source("helpers.R")
load('04.Rdata')
data<-list("data"=data_results,"data_results_table"=data_results_table)
shinyServer(function(input,session) {
source("server2.R",local = TRUE)
source("server3.R",local = TRUE)
})
并加载数据