Developing Shiny App as a Package and Deploying It to Shiny Server

developing shiny app as a package and deploying it to shiny server

When I make shiny applications as a stand-alone package, I usually organize the files as so:

In the R directory:

  • All of my methods to support the application (these should be exported if they will be used in either the ui.R, server.R, or global.R files)
  • A launch_application function

The definition of launch_application is similar to:

launch_application <- function(x, ...)
{
shiny::runApp(appDir = system.file("application", package = [my_pkg]),
...)
}

In the inst directory

  • application/server.R
  • application/ui.R
  • application/global.R

After building and installing the package, I then just need to run

library(my_pkg)
launch_application(...)

Deploying packaged shiny-app on shinyapps.io

You could try to upload your package on CRAN and call it inside your shinyApp. This would give you all the functionality of your package and everyone else who might be interested in your package aswell. The downside of this is, that you will have to go through a lot of formating, documenting, error checking, rebuilding, etc.. CRAN has quite some strict rules on how the package must "look" like to accept and host it.
At least you have to have 0 errors and 0 warnings when checking it.


If you dont want to host it on CRAN you can just include all the functions from the package in a directory and source those files in your Shinyapp. You can do that inside a global.R file or even inside the server.R file, but outside the server function.

----- ./App_Directory/

---------- global.R

---------- server.R

---------- ui.R

---------- www/

--------------- function1.R

--------------- function2.R

--------------- function_etc.R

Then you would source them by including those commands in your global.R / server.R file:

source("www/function1.R")
source("www/function2.R")
source("www/function_etc.R")

You could also just put all the functions directly in your global/server file, but sourcing them is probably more organized and easier to maintain.

----- ./App_Directory/

---------- global.R

---------- server.R

---------- ui.R



Related Topics



Leave a reply



Submit