Workflow for maintaining different versions of a Shiny app
Each app has a different title, different data, some differences in branding etc. but otherwise the code is very similar.
I’m having trouble maintaining these apps. When find and fix a bug I currently have to go through 5 different apps and make the change each time.
Does anyone have good suggestions on how to handle this? Git branches? I know the best solution would be to have one app and upload different data, but that’s not possible unfortunately.
I’d like to keep using shinyapps.io, but I’m open to hosting the apps somewhere else if it makes my workflow better.
2 Solutions collect form web for “Workflow for maintaining different versions of a Shiny app”
As I wrote in the comment
shinyModules() will help you: https://shiny.rstudio.com/articles/modules.html
Shiny modules are to shiny functions, like ordinary functions are to repeating code.
Or to put it differently:
- Repeating code –> function
- repeating shiny function –> shiny module
As the documentation is a bit complicated here and there, i wrote a simplified example here:
Create a reactive function outside the shiny app.
You could store all the shiny modules in a file
modules.R and add a
global.R script to each of the apps that loads the modules (
source("../modules.R"). Then you only have to update the functions within
modules.R. That change of structure might take a while in the beginning. But, i think in the long run it pays off for more complex apps.
I ended up making a library that contained most of the code I needed for the apps, as suggested by Adam Spannbauer in the comments.
It’s not perfect; I still have some duplication and I have to have the library on GitHub so that it will work with shinyapps.io. However, it’s a big improvement on what I was doing previously.