简体   繁体   English

如何在 ShinyApp 中只加载一次 Rdata 文件

[英]How to load Rdata file only once in ShinyApp

I have deployed a shinyapp which uses a.Rdata file of ~700Mb.我已经部署了一个使用 ~700Mb 的.Rdata 文件的闪亮应用程序。

The Rdata file is loaded in server-inputdata.R file and the server.R file looks like as shown below: 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) 
})

Here, server2.R and server3.R has visualization code which uses the data loaded from.Rdata file in server-inputdata.R此处, server2.Rserver3.R具有可视化代码,该代码使用从server-inputdata.R中的.Rdata 文件加载的数据

Whenever the app is loaded, the Rdata file is getting loaded for each user.每当加载应用程序时,都会为每个用户加载 Rdata 文件。 Could someone help how to load the data only once and provide immediate access to the users.有人可以帮助如何只加载一次数据并为用户提供即时访问。 Checked a similar thread here https://stackoverflow.com/questions/31557428/r-load-only-once-a-rdata-in-a-deployed-shinyapp which did not help to solve my issue.在这里检查了一个类似的线程https://stackoverflow.com/questions/31557428/r-load-only-once-a-rdata-in-a-deployed-shinyapp这无助于解决我的问题。

Here is the code in server-inputdata.R这是server-inputdata.R中的代码

inputDataReactive <- reactive({
    load('04.Rdata')
    return(list("data"=data_results,
                "data_results_table"=data_results_table))
    print("uploaded data")
})

Try putting your source line: source("server-inputdata.R",local = TRUE) outside of your server function, as in:尝试将源代码行: source("server-inputdata.R",local = TRUE)放在服务器 function 之外,如下所示:

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) 
})

Removing the reactive function did the trick.删除反应性 function 就可以了。

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, output,session) {
source("server2.R",local = TRUE)
source("server3.R",local = TRUE) 
})

And loading the data o并加载数据o

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM