A shiny
Two that are related.
The timer
It is quite easy to get carried away and muddle the flow.
Code Organization: - Clear and concise names - Comments for complex code - Can big functions be made smaller - Copy/paste and functions - Tangles versus isolations
Chapters 18 Functions and 19 [Modules] seek to achieve some of these ends.
renv
or packrat
for package dependenciesconfig
package for non-package dependenciesGithub is most common for source storage though it is by no means the only such tool. Tools for integrating testing are the key to the CI/CD part.
Code reviews are common practice in professional development shops. Different approaches with different people often improve our code. Two aspects.
Two Basic Types:
Why functions?
The key benefits of a function in the UI tend to be around reducing duplication. The key benefits of functions in a server tend to be around isolation and testing.
golem
R packages have a standard form of organization with code in R/
.
An example: - Copy/pasting sliders - A function for creating sliders - Functionally programming the sliders - The UI is data; functions given data
It is much easier to debug and test your code if you can partition it so that reactivity lives inside of server(), and complex computation lives in your functions.
When looking at a reactive expression or output, there’s no way to easily tell exactly what values it depends on, except by carefully reading the code block. A function definition, however, tells you exactly what the inputs are.
Let’s walk through the example.
Modules are functions but, rather than being defined for a UI or server, they typically integrate both. They are essentially a namespace for their environment. They are basically mini-apps that define a module UI and a module Server.
Modules are black-boxes that match together the UI and server. This means two important things.
Anything from outside the module has to be passed – think sandboxes.
An important part of the mental model.
First, this is the same advice as Emily Riederer’s advice on markdown-driven development.
Second, this requires knowledge of exactly how R packages are built. On R packages, there’s a great resource though more on this next time with golem
[or the rhinoverse].
Four key levels:
testthat
Two main issues:
Your data: you want to make sure an attacker can’t access any sensitive data.
Your computing resources: you want to make sure an attacker can’t mine bitcoin or use your server as part of a spam farm.
There are two parts to improvement. The first is shared with essentially any R code using the three principles on the last slide: benchmark, profile, and optimise. Because shiny’s are whole systems, there is also…
Communicating With Data: Week 12 (10 Apr 2023)