I have been trying to display the memory usage of each object used in my R Shiny app when run on R Shiny Server, so as to identify memory leakages. In R, I can call ls() or objects() and get all that information. As soon as I try displaying this info in a Shiny app, either through renderText() or renderDataTable() off of a dataframe, it's all blank. I am guessing there is an issue with the environment the functions ls() and objects() are looking in. Anybody ran into that issue before?
Here is a short example (the key is to specify the environment that you want to investigate):
library(shiny)
runApp(list(
ui = fluidPage(
tableOutput('foo')
),
server = function(input, output) {
x1 <- 1:100
x2 <- rbind(mtcars, mtcars)
env <- environment() # can use globalenv(), parent.frame(), etc
output$foo <- renderTable({
data.frame(
object = ls(env),
size = unlist(lapply(ls(env), function(x) {
object.size(get(x, envir = env, inherits = FALSE))
}))
)
})
}
))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With