Home:ALL Converter>Saving R Shiny app as a function with arguments passed to the shiny app

Saving R Shiny app as a function with arguments passed to the shiny app

Ask Time:2018-03-25T06:12:32         Author:iceberg

Json Formatter

I am building an R package that has a function to launch a shiny app. I would like that function to include an argument to be passed to the app. The only way I found to work is setting a global value, and then having the app use that global value:

launch_app <- function(MonteCarlo=1000){
  MonteCarlo_global <<- MonteCarlo
  shiny::runApp(appDir = system.file("app.R", package="my_package"))
}

Is there a better way to pass my "MonteCarlo" argument to be used throughout the shiny app? Please note I'm trying to avoid simply including "MonteCarlo" as one of the input options within the app itself. I'd rather have the user not worry about it. But, if desired the knowledgeable user can control it when launching the app.

Author:iceberg,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/49470474/saving-r-shiny-app-as-a-function-with-arguments-passed-to-the-shiny-app
yy