## Day to day development with {golem}

Now that you’re all set with your project init, time to move to development :)

App development should happen through the dev/02_dev.R file, which contains common commands for developping. ## Launching the app

To run the app, go to the dev/run_dev.R file, and run the all thing.

## dev/02_dev.R

The golem::add_module() functions creates a module in the R folder. The file and the modules will be named after the name parameter, by adding mod_ to the R file, and mod_*_ui and mod_*_server to the UI and server functions.

golem::add_module( name = "my_first_module" ) # Name of the module

The new file will contain:

# mod_UI
mod_my_first_module_ui <- function(id){
ns <- NS(id)
tagList(

)
}

mod_my_first_module_server <- function(input, output, session){
ns <- session$ns } ## To be copied in the UI # mod_my_first_module_ui("my_first_module_1") ## To be copied in the server # callModule(mod_my_first_module_server, "my_first_module_1") In order not to make errors when putting these into your app, the end of the file will contain code that has to be copied and pasted inside your UI and server functions. ### Add dependencies To be called each time you need a new package as a dependency: usethis::use_package("pkg") ### Add tests Add more tests to your application: usethis::use_test( "app" ) ### Add a browser button Learn more about this: https://rtask.thinkr.fr/blog/a-little-trick-for-debugging-shiny/ golem::browser_button() ### Add external files These functions create external dependencies (JavaScript and CSS). add_js_file() creates a simple JavaScript file, while add_js_handler() adds a file with a skeleton for shiny custom handlers. golem::add_js_file("script") golem::add_js_handler("script") golem::add_css_file("custom") ## Adding these external resources to your app You can add any external resource (JS, css) into inst/app/www. Then, You’ll need to point to these external resources in golem_add_external_resources(). For example, if you’ve created a CSS file with golem::add_css_file("custom"), you can add the file with: tags$link(rel="stylesheet", type="text/css", href="www/custom.css")

Put these links into R/app_ui.R, in the golem_add_external_resources() function.

You can also list here the use of other packages, for example useShinyalert() from the {shinyalert} package.

Note: we’ve chosen to leave it “raw”, in the sense that there is a addResourcePath and a tags\$head. If you’re comfortable with {htmltools}, you can build a htmltools::htmlDependency.

## Documentation

### Vignette

usethis::use_vignette("shinyexample")
devtools::build_vignettes()

### Code coverage

usethis::use_travis()
usethis::use_appveyor()
usethis::use_coverage()

## Using {golem} dev functions

There’s a series of tools to make your app behave differently whether it’s in dev or prod mode. Notably, the app_prod() and app_dev() function tests for options( "golem.app.prod") (or return TRUE if this option doesn’t exist).

Setting this options at the beginning of your dev process allows to make your app behave in a specific way when you are in dev mode. For example, printing message to the console with cat_dev().

options( "golem.app.prod" = TRUE)
golem::cat_dev("hey\n")
options( "golem.app.prod" = FALSE)
golem::cat_dev("hey\n")
#> hey

You can then make any function being “dev-dependant” with the make_dev() function:

log_dev <- golem::make_dev(log)
log_dev(10)
#> [1] 2.302585
options( "golem.app.prod" = TRUE)
log_dev(10)