0

I am building an application on RShiny using the Phyloseq library, and the code is starting to become unmanageable. I saw other code examples where programmers like Joey711 source their code from other files.

Here is an example:

 # Bar
   source("panels/panel-server-bar.R", local = TRUE)
 # Tree
   source("panels/panel-server-tree.R", local = TRUE)

My current code is in two large server and ui files and I'm not sure how to break it up.

Merely splitting the code into multiple files breaks the program, but it works all together. Does anyone have an approach to breaking up a large codebase in R? Does the Global.R file allow you to call multiple code files in the app?

Ariel A
  • 474
  • 4
  • 14
  • 1
    A guess: if you move your `.R` files to a subdir from the "main" dir, are they looking for resources in a specific path? You might look at relative paths to find them. You might also consider removing `local=TRUE`, just going with `source("panels/panel-server-tree.R")` (et al). Can you expand on *"mess of errors"*? I disagree to the premise that code must be written as a single monolithic file. – r2evans Feb 24 '19 at 21:31
  • What I really want to understand is a way to make code into separate manageable parts. The errors I get is that some of the graphics that I created work fine, but others are broken. Its errors like this which are probably more syntax based when I merged the files: Error: subscript out of bounds or objects not being found. One graphic appears but it takes at least twice as long as it did to load before I merged the code. – Ariel A Feb 24 '19 at 23:29
  • . If you have experience with RShiny, do you know of a way of keeping separate files and calling them all in one app, meaning can you stitch separate parts of one app into a unified version. – Ariel A Feb 24 '19 at 23:31
  • 1
    I use `source(...)` (as you show, but without `local=TRUE`) and it generally works well. I don't know what kinds of errors you are getting, so it's difficult for me to make any suggestions beyond that. – r2evans Feb 25 '19 at 00:04
  • 1
    What you are trying to do is "modularizing" your app, see [Shiny modules](https://shiny.rstudio.com/articles/modules.html) – JohnCoene Feb 25 '19 at 09:10
  • Thank you JohnCoene. That page is what I was looking for. I saw that page a number of times, but I didn’t understand that when they were talking about modulariazing pages, they were actually giving me the solution I needed. I just didn’t understand what they meant by modularizing until you pointed it out here. Thank you again. – Ariel A Feb 25 '19 at 14:44

0 Answers0