Uploading .RData file to session, but object not uploaded to Shiny

I got the analysis results in R (an object named obj ) and saved it as a .RData file obj-result.RData . Now in Shiny, at the beginning of the ui.R file, I put load("obj-results.RData") so that every time Shiny is executed, this object can be loaded into the R session, i.e. I expect the obj object to be available for use in subsequent steps, such as obj@data , obj@sample , etc.

However, I found that load will not make obj accessible in the current R session, so Shiny could not find the required quantities. Is there something I missed when loading the .RData object? Thank you very much!

+4
source share
2 answers

The answer is that whenever an object is used in ui.R and / or server.R , the corresponding objects must be loaded into the same file. Otherwise, the brilliant will not know where to find the object from other files (even they are in the same directory and downloaded).

+5
source

I also upload the .RData file in my deployed ShinyApp; my application runs from this file. It was also hard for me to understand how loading works. In this example , the load(...) server.R is in server.R . This method did not work in my ShinyApp (the application was displayed, but immediately turned gray) - I do not know why. The solution was only to put the load(...) operator in the global.R file: load("./data/obj-result.RData", envir=.GlobalEnv) .

+2
source

Source: https://habr.com/ru/post/1491434/


All Articles