Please see this related article:
For applications defined this way, the server.R file must return the server function, and the ui.R file must return the UI object (in this case, the UI object is created by fluidPage() ). In other words, if the files contained other code (like utility functions) you must make sure that the last expression in the file is the server function or UI object.
The above is also fulfilled if server.R returns a anonymous function (as long as it is the last expression in the file).