Loading a Shiny application as an R package

I was reading here that in Shiny 1.5 applications will automatically source files in the R/ folder. This is great.

I'm wondering if one could also load a Shiny application as an R package. In my case, I'm developing an R package with an accompanying Shiny interface. Is there a best practice for organizing this type of tool in such a way that users can install/load the functions/objects as an R package as well as spin up the Shiny interface?

1 Like

You can absolutely load a Shiny application within an R package!

Take a look at the bottom of Shiny - Sharing apps to run locally.


As an example, I'm not sure what the best practice is, but I previously followed the directions on the link above by putting my shiny app in the inst/ folder of my package and writing a runApp() function in my package to run the app.

My package/app is by no means a good general example, but it seems to work:

launchApp.R
application directory within package repo

I've been placing any big apps or apps that I want to share inside R packages for 5 years and it's been working out great. So yes, it's a great idea. It's best to keep all the "business logic" of your app inside the R folder as separate functions and files, so that they can be tested easily (since you're now in a package - you get a testing framework!). The DESCRIPTION file is a great way to make it clear what package dependencies the app needs. There are lots of benefits for this.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.