Day to Day Dev with {golem}

Colin Fay


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 developing.

Launching the app

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


Add dependencies

To be called each time you need a new package as a dependency:

About package dependencies.

Add modules

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.

The new file will contain:

At the end of the file, you will find a piece of code that has to be copied and pasted inside your UI and server functions.

Add function files

golem::add_fct( "helpers" ) 
golem::add_utils( "helpers" )

These two function create R/fct_helpers.R and R/utils_helpers.R, two file you can use to add business logic functions.

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.

Note: While the general philosophy of {golem} is being based on the idea that you’re building a package, these functions can be used outside of a {golem} project.

Note that you can also download external CSS and JavaScript files with:

Adding these external resources to your app

You can add any external resource into inst/app/www.

JavaScript and CSS are automatically linked in the golem_add_external_resources() function. If you add other resources (example images), you can link them in the app with the www prefix:

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

Add a data-raw folder

If you have data in your package:

About data in a package.

Add tests

Add more tests to your application:

About testing a package.



About package Vignette.

Code 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( "") (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( "" = TRUE)
options( "" = FALSE)
#> hey

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

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