pdubois
pdubois

Reputation: 7800

How to organize Rmarkdown files (with Shiny runtime) inside a package

Currently I have an analysis project which I treated as package. So currently I have the following structure:

mycoolanalysispackage/
|-- .Rbuildignore
|-- .gitignore
|-- DESCRIPTION
|-- NAMESPACE
|-- inst
|-- vignettes
|-- R
`-- mycoolanalysispackage.Rproj

At the end I usually produce many Shiny applications as Rmarkdown-flexdashboard file with Shiny runtime.

  -- app1/
       |-- index.Rmd
  -- app2/
       |-- index.Rmd

My question is, in which package subdirectory should I put those application directories (along with their index.Rmd files)?

I also have local Shiny Server, what's the best way to link that Rmarkdown-flexdashboard app to that server?

Upvotes: 3

Views: 330

Answers (1)

Joris Meys
Joris Meys

Reputation: 108543

As with everything else, you place them in a subfolder of the inst folder when developing the package. When the package is installed, all folders in the inst folder will be moved to the package folder, and hence can be used as subfolders. So

mycoolanalysispackage/
|-- .Rbuildignore
|-- .gitignore
|-- DESCRIPTION
|-- NAMESPACE
|-- inst
     |-- app1/
       |-- index.Rmd
     |-- etc...
|-- R
`-- mycoolanalysispackage.Rproj

To access the files from within an R function, you can use system.file:

system.file("app1","index.Rmd",package = "mycoolanalysispackage")

will give you the exact path to the index.Rmd of app1. That result can then be used to deploy the app using the appropriate functions.

See also the manual Writing R Extensions (scroll down a bit)

Upvotes: 1

Related Questions