I have used the below code to see the dataframes, matrices, functions and so on in my environment.
But is there a way to use this below code in server.R so that I can see what all dataframes, matrices are there in my application? I tried below code in my server.R but it not listing . Can anyone please help?
The result of ls() depends on the environment for which it is called. You specified the Global Environment so it returns objects at that level. I modified the code to have ls() calls in three different places with the result stored in the variable called Obj. If you change which one is active (be sure to have comment marks on the other two), you can see the different results.
library(shiny)
library(purrr)
MyDF <- data.frame(A = 3)
MAT <- matrix(1:4, nrow = 2)
X <- 34
#Obj <- ls()
ui <- pageWithSidebar(
headerPanel("My First Shiny App"),
sidebarPanel(
),
mainPanel(
tableOutput("myTable")
)
)
server <- function(input, output, session){
#Obj <- ls()
output$myTable <-renderTable({
InnerDF <- data.frame(Z = 1:5)
Obj <- ls()
purrr::map_dfr(Obj,
~tibble(object_name = .,
object_class=class(get(.))[[1]]))
})
}
# Run the application
shinyApp(ui = ui, server = server)
Thanks for the time you have given. Almost 80 of the problem is solved. I have modified your code a little bit. Actually let us say there are lots of functions in server.R. Do i have to name Obj <- ls() everytime ? Please refer below section3
Also from your logic the output I get is below in section1
section1 below.
object_name object_class
InnerDF data.frame
Can we add another column and tell user that it is coming from myTable as shown below is section2
Since every function defines a new environment when it is called, I think you have to have a ls() inside of each function to capture the objects unique to it. It is possible to look at environments preceding the function, but that is getting beyond anything I have done. If you want to look into that, there is a chapter about environments in the Advanced R book.
Thanks, But your are passing lsDF$output <- "MyTable". Actually it should be reactive right. because we have myTable in output$myTable. What i meant actually was this output. But actually you tried passing as a object. Makes sense?