Reputation: 61
I am just learning to program in R and wrote my question best I could so I apologize in advance if it isn't quite clear. Be easy on me.
I am writing a Shiny program and I define some variables within the shinyServer function in the Shiny package for R however I'd like to be able to access these variables in the console to make sure my code is doing what I'm planning. As it is they don't appear as global variables.
Here is my server.R code. I'd like to be able to see the inFile variable in the console to see what it contains.
shinyServer(function(input, output) {
output$picture <- renderPlot({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
image0 <- readImage(inFile$datapath)
image1 <- image0[3265:3825,660:770,1:3]
profile_image1 <- rowSums(image0)
plot(-1*profile_image1)
})
})
Upvotes: 2
Views: 483
Reputation: 489
Try using something like this in your server.R
observe({
on.exit(
assign("name of new object in .GlobalENv",
expression/object, .GlobalEnv)
)
})
This will create an object in .GlobalEnv with the name you have defined when exiting the application.
Hope it works!
Upvotes: 1
Reputation: 683
well the easiest way would be to assign the variable globally with <<
and when the execution finishes you will be able to manipulated them in your console.
Upvotes: 0
Reputation: 3794
The easiest thing is to use CTRL-ENTER to run the portion of code that is of interest, excluding any reactive functions.
So in your case, you will need to define inFile to be a test file in the console (you cannot execute a partial reactive function to read input$file1
otherwise.
> inFile <- "/my/test/file"
Once you have that you can simply select and run the rest inside the brackets. To wit:
if (is.null(inFile))
return(NULL)
image0 <- readImage(inFile$datapath)
image1 <- image0[3265:3825,660:770,1:3]
profile_image1 <- rowSums(image0)
plot(-1*profile_image1)
And that allows you to run it the whole portion of the code in your console. But more importantly you can walk through it line by line (CTRL-ENTER with the cursor on a line will execute the line).
Now this is the really easy and fast way to start out. If you want to get more serious about debugging (and you do want that as you program more), you will need to read Lesson 10 as suggested by hrbrmstr in the comments and start working with the error console on your browser and perhaps the log files if you use shiny-server.
Upvotes: 0