Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workflow for maintaining different versions of a Shiny app

Tags:

git

r

shiny

Lately I have been making several very similar Shiny apps for different clients and hosting them on shinyapps.io.

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.

like image 311
Mhairi McNeill Avatar asked Jan 19 '26 09:01

Mhairi McNeill


2 Answers

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.

like image 173
Tonio Liebrand Avatar answered Jan 20 '26 21:01

Tonio Liebrand


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.

like image 40
Mhairi McNeill Avatar answered Jan 20 '26 21:01

Mhairi McNeill