Sharing www directory across Shiny apps


I am trying to figure out how to share Shiny's www directory across apps, such that I can share a stylesheet. My directory structure is such that I have a Git repo that contains many Shiny apps. I also have a static assets directory in that repo. One might imagine that its directory structure is:

├── app1/
│   ├── server.R
│   └── ui.R
├── app2/
│   ├── server.R
│   └── ui.R
├── app3/
│   ├── server.R
│   └── ui.R
├── assets/
│   └── style.css

I'm aware that all the Shiny apps expect to have a www directory inside of them. Naturally, I'd prefer to not need to copy/paste/rename the assets directory.

I've tried using addResourcePath, i.e. addResourcePath('www', '../assets'), but that doesn't seem to work. I've also tried pointing my UI code at the shared directory, i.e. tags$link(rel = "stylesheet", type = "text/css", href = "../../assets/style.css"), but that also does not seem to work for me.

What's the recommended way of telling each Shiny app to find this assets directory?

Many thanks.

If you're on macOS or Linux, maybe you could cheat and have symlinks to a common www folder?

(this would def. be a last-ditch solution!)

Take a look at the addResourcePath function. You can use it to mount any directory to a Shiny URL.

1 Like

This is a nice idea that had somehow eluded me. I will set that up as part of our build script.

That was the first thing I tried, but for whatever reason this wasn't playing nicely with the static assets. I'm not quite sure why, as there was little debug information available.