简体   繁体   中英

How to load Rdata file only once in ShinyApp

I have deployed a shinyapp which uses a.Rdata file of ~700Mb.

The Rdata file is loaded in server-inputdata.R file and the server.R file looks like as shown below:

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

Whenever the app is loaded, the Rdata file is getting loaded for each user. 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.

Here is the code in 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:

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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