Thanks, @jim89. Modules are mainly for reusable pieces of code. This is slightly different in that I just want to put the tabPanel code into its own file and somehow source it in.
You can define a piece of UI logic, save it to a variable, and then call that variable to actually put the UI in place (I do that when building in shinydashboard to help me understand my code better). So you could probably define the logic in a separate file, either saving it as a variable, or just wrapping the logic a a function with no arguments, then source the file and/or use the function in your UI. A module might still work (if I'm correct in thinking that a module doesn't necessarily need to have server logic), but just using a function that creates the UI and calling that might be simpler (but then you're already half way to a module )
I recommend a strategy similar to the ones that @jim89 suggested:
create a function that calls the tabPanel code
save the function in global.R (or its own separate R file which you source explicitly somewhere in the app)
If the tabPanel code will be reused in the same app then you should isolate it by creating a module instead of a function.
I found this post by @greg to be very helpful in demostrating how a ui can be simplified by grouping ui elements together in a function.
Tangentally, I've also found that once an app is 75% completed (all the features are in place, but there's still some tweaking and cleaning left to do) it's helpful to convert the app into a package and document the functions/modules. More on that here.
To answer your specific question: let's assume you want to save everything within your tabPanel() with the exception of the title in a file named snippet.R., you would call that file as follows:
tabPanel("Export .Rdata",
source(snippet.R, local = TRUE)[1]
)
Not calling the [1] at the end would evaluate that file to TRUE, rather than actually sourcing the code.
@daattali and @bogdanrau your suggestions work (almost) perfect. Here is a sample of my server file, which has one issue
options(shiny.maxRequestSize=50*1024^2) # 50 mg limit on file upload
source('Rcode/codePack.R')
source('Rcode/libPack.R')
shinyServer(function(input, output, session) {
source(file.path("Rcode/serverFiles", "someCode.R"), local = TRUE)$value
}) # end Program
this program reads in a large file, which is why I have the requestSize modified. When the code that lives inside "someCode.R" is actualy in the server file, no problems. But, when I source that code in as in the example above, I run into memory limits suggesting the adjustment to memory is seemingly ignored?
Also, this program runs on a shiny server, so users access this from a URL. Seems that if we run it locally (on my own machine to test), everything works as expected.
But, when run from the shiny server same code runs into memory errors?
So my suggestion works when sourcing scripts related to the UI into ui.r (or other ui scripts). When you're sourcing into server, you should be able to just:
options(shiny.maxRequestSize=50*1024^2) # 50 mg limit on file upload
source(‘Rcode/codePack.R’)
source(‘Rcode/libPack.R’)
shinyServer(function(input, output, session) {
source(file.path("Rcode/serverFiles", "someCode.R"), local = TRUE)
}) # end Program
Also, if the 50MB limit works when running locally but not when running in shiny server, it sounds like it's related more to shiny server itself, rather than your scripts.
Thanks, @bogdanrau. To be clear, the 50MB limit does work on the Shiny Server when the actual code is in the server.R file. But, when I source that code in from another file, it seems to not work.
For example, the mem limit is seemingly ignored here:
shinyServer(function(input, output, session) {
source(file.path("Rcode/serverFiles", "someCode.R"), local =