Setup Your R Environment

js4shiny

I’ve created a companion R package for this workshop called js4shiny. Installing the package with its dependencies will ensure that you have the R packages needed for the workshop. The package also provides access to the examples and exercises used in the workshop and includes some helpful tools that you can use after the workshop while learning and working with JavaScript.

💻 To install the package, use devtools.

# install.package("devtools")
devtools::install_github("gadenbuie/js4shiny", dependencies = TRUE)

Be sure to include the dependencies = TRUE!

If you’re installing devtools for the first time, you may find the System Setup of the R Packages book to be helpful.

ℹ There is a minor issue with rmarkdown limited specifically to version 2.0. If you have rmarkdown 2.0 installed, I recommend updating to a newer version. The current version of rmarkdown on CRAN is . If the CRAN version is 2.0.5 or higher, install from CRAN; otherwise use

devtools::install_github("rstudio/rmarkdown")

Snippets

I’ve created a set of code snippets for RStudio that are useful for the types of tasks we’ll cover in the workshop. You can find the source files in the js4shiny package repository.

To install the snippets, you can use the js4shiny package.

js4shiny::snippets_install()

If you haven’t installed snippets before, the newly installed js4shiny snippets will mask the built-in RStudio snippets.

If you do have snippets installed, the new snippets should be written added to your snippets list. You may wish to make a backup copy of your existing snippets files, which you can find by running the following code (requires the fs package).

# rstudio < 1.3
snippets_dir <- fs::path_home_r(".r", "snippets")

# rstudio >= 1.3+
# snippets_dir <- fs::path_home_r(".config", "rstudio", "snippets")

fs::file_show(snippets_dir)

Or you can manually install the snippets by copying and pasting them into the snippets editor in RStudio, which is available under Global Options > Code > Edit Snippets button. You can find more information and detailed instructions about using snippets at Code Snippets on the RStudio Support page.

Other R Requirements

I’ve included all of the packages that we’ll need in the dependencies of js4shiny except for the tidyverse. Please make sure you have at least the core tidyverse packages installed.

The final R detail is that we will be building a package during the workshop when we create an htmlwidget. We won’t focus on the mechanics of package building in the workshop. If you’re not familiar with package development, I recommend taking a look a R Packages by Hadley Wickham and Jenny Bryan. At a minimum, please review the System Setup chapter, in particular the section on the R build toolchain to ensure that your laptop will be ready to build a package.

Previous
Next