2
votes

I am learning Shiny and need some help please.

I need to load a very large data.frame from a saved workspace (RData). Once loaded I need to perform analyses and output these to the UI.

I have placed the following code in server.R but it doesn't load the data and then throws an error:

shinyServer(function(input, output) {
  load("c:/temp/ws1.RData")  
  output$balance_matrix <- renderTable({
    Transaction_history
  })

})

> Error in func() : object 'Transaction_history' not found

First, what am I doing wrong here?

Secondly, is this the best place to load the workspace?

Thirdly, can I load it outside the function at the top or will it not be available in the function then?

Thanks

1

1 Answers

2
votes

Rather than saving and trying to load the workspace, I'd recommend saving the file individually like,

saveRDS(Transaction_history, "C:/temp/ws1.RData")

and then load it in Shiny like,

Transaction_history <- readRDS("C:/temp/ws1.RData")

This method will focus on this file by itself. From the ?load documentation,

load() replaces all existing objects with the same names in the current environment (typically your workspace, .GlobalEnv) and hence potentially overwrites important data.