Suppose I have two functions like the ones below. How can I make inFile and inFileName global so that I do not have to repeat inFile <- input$file and inFileName <- inputFileName in all the different renderText context? In other words, How can i calculate the variables so that they can be used repeatedly through the server function?
You can create reactive values with them and then call the reactive values inside of the renderText (or any other render, reactive, or observe functions).
It is worth noting that you don't have to assign those variables in each render function or their own reactive functions, you could just pass input$file$name directly into your glycoPipe functions
I get the following response:
" 1: shiny::runApp
Error in .getReactiveEnvironment()$currentContext() :
Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)"
What does this mean?
Did you add parenthesis when you call inFileName() in the renderText functions? Now that it is inside of a reactive expression you need to call it like a function (because it is essentially a function).
Yes, it is, but misunderstood the request from cderv. I thought he was asking to write my working example. I will make the change. Thank you for telling me.
Tyler is correct that in this instance you should re-write and place inFile in a reactive context, again-this is the correct way to solve this problem. However, there are some exception cases where you can assign using the scoping assignment <<- to do what the question asked.
That is true, although using <<- can lead to unintended consequences that can be hard to diagnose and may cause your code to produce inaccurate results without realizing it.
Tyler, 100% True! I simply wanted to mention it since question was phrased about making a server variable global even though that wasn't what Giuseppa really needed to do.