3
votes

I would like to develop a bunch of Shiny apps, each of them working (and editing) the same set of data. Is that feasible and if yes, how should the project be structured?

1 Shiny app

The way I am used to structure my shiny app is the following:
enter image description here

2+ Shiny apps

Is there a way to refer to another location for the data, or to store apps within the root folder this way:

enter image description here,

each app using data located in the data folder. For each app, ui.R, server.R and global.R are stored in the 'app_i' folder.

From what I know ui.R, server.R and global.R should always be located at the root of the project, which makes it impossible to work with multiple apps on the same dataset..

Thank you in advance for your views on this, and for sharing best practices.

Regards

1

1 Answers

7
votes

ui.R, server.R and global.R have to be in the root directory of your app but any of these can access files outside the root. Few options you have here are:

  • use absolute path to your data directory when you access files

    DATA_PATH <- "/path/to/data/"
    
  • use relative path

    DATA_PATH <- file.path(getwd(), "../data/")
    
  • use symlinks

    .
    ├── app1
    │   ├── data -> /path/to/data
    │   ├── server.R
    │   └── ui.R
    ├── app2
    │   ├── data -> /path/to/data
    │   ├── server.R
    │   └── ui.R
    ├── app3
    │   ├── data -> /path/to/data
    │   ├── server.R
    │   └── ui.R
    └── data
        ├── bar.csv
        └── foo.csv
    
  • for read only data sets you can create a data-only package using standard R tools

  • if data has to be written in a safe manner by multiple apps use database as a backend. It can be either file based solution like SQLite or a proper server.
  • use lightweight web service to fetch/update your data