Calling a function from a reactive context and calling a second function from the first one

Yes, you can define a function above the ui or between the ui and the server. You can call the function from the server. It works fine as long as you pass it every variable it needs to run. These are called global functions.

The advantage of a global function is that it loads once with the app and doesn't have to be reloaded every time a new session starts, as it would if it lived inside the server function.

However what such a function cannot do is access any variables defined inside the server function; you must pass everything required in parameters to the function call.

Also note that you can also define global variables, but since every session can see and change these, it's almost never what you actually want. App-global functions are ok, app-global variables typically aren't.

Tom

2 Likes