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
, orglobal.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
How to Rbind Only the Common Columns of Two Data Sets
R Shiny Loop to Display Multiple Plots
Generally Disable Dimension Dropping for Matrices
How to Automatically Load Data in an R Package
How to Change Name of Factor Levels
How to Add Legend to Geom_Smooth in Ggplot in R
Max and Min Functions That Are Similar to Colmeans
1-Dimensional Matrix Is Changed to a Vector in R
Extract Last Non-Missing Value in Row with Data.Table
Repeat the Re-Sampling Function for 1000 Times? Using Lapply
Append Multiple CSV Files into One File Using R
How to Replace Lower/Upper Triangular Elements of a Matrix
Update Plot Within Observer Loop in Shiny Application
Converting Yearmon Column to Last Date of the Month in R
Why Does Subsetting a Column from a Data Frame VS. a Tibble Give Different Results