---
title: "Deploying Apps with {golem}"
author: "Colin Fay"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{c_deploy}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

<script type="text/javascript">
$(document).ready(function () {
  window.initializeCodeFolding("show" === "show");
});
</script>

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>", 
  eval = FALSE
)
```

## About the `run_app()` function

When launching the app, you might have noticed that the `dev/run_dev.R` function calls `run_app()`, which has the following structure:

```{r}
run_app <- function(
  ...
) {
  with_golem_options(
    app = shinyApp(
      ui = app_ui, 
      server = app_server
    ), 
    golem_opts = list(...)
  )
}

```

This function might looks a little bit weird, but there's a long story behind it, and you can read more about it [there](https://rtask.thinkr.fr/blog/shinyapp-runapp-shinyappdir-difference/).

But long story short, this combination of `with_golem_options` & `golem_opts = list(...)` allows you to pass argument to the function to be used inside the application, from UI or from server side, which you can get with `get_golem_options()`.

```{r}
run_app(this = "that")
# And in the app 
this <- get_golem_options("this")
```

The idea is to provide more flexibility for deployment on each platform you want to run your app on.

## Deploying Apps with `{golem}`

The `dev/03_deploy.R` file contains function for deploying on various platforms. 

### RStudio Products

```{r}
golem::add_rstudioconnect_file()
golem::add_shinyappsio_file()
golem::add_shinyserver_file()
```


### Docker 

```{r}
# If you want to deploy via a generic Dockerfile
golem::add_dockerfile()

# If you want to deploy to ShinyProxy
golem::add_dockerfile_shinyproxy()

# If you want to deploy to Heroku
golem::add_dockerfile_heroku()
```

