Skip to content

Commit f7fbd76

Browse files
committed
Built site for [email protected]: 1d0c151
1 parent a85b07e commit f7fbd76

File tree

11 files changed

+156
-39
lines changed

11 files changed

+156
-39
lines changed

articles/use-application-audit.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

articles/use-ci.html

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

articles/use-ci.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,26 @@ dependencies. [renv](https://rstudio.github.io/renv/) uses the same
142142
mechanism that is used by shinyapps.io and RStudio Connect.
143143

144144
[renv](https://rstudio.github.io/renv/) auto-generates these three files
145-
using is`renv::init()` and `renv::snapshot()`.
145+
using
146+
is[`renv::init()`](https://rstudio.github.io/renv/reference/init.html)
147+
and
148+
[`renv::snapshot()`](https://rstudio.github.io/renv/reference/snapshot.html).
146149

147150
| File | Usage |
148151
|:------------------|:-----------------------------------------------------------------------------------------------------|
149152
| `.Rprofile` | Used to activate [renv](https://rstudio.github.io/renv/) for new R sessions launched in the project. |
150153
| `renv.lock` | The lockfile, describing the state of your project’s library at some point in time. |
151154
| `renv/activate.R` | The activation script run by the project `.Rprofile`. |
152155

153-
To create `.Rprofile` and `renv/activate.R`, call `renv::init()` within
154-
your App project. To create / update `renv.lock`, call
155-
`renv::snapshot()`.
156+
To create `.Rprofile` and `renv/activate.R`, call
157+
[`renv::init()`](https://rstudio.github.io/renv/reference/init.html)
158+
within your App project. To create / update `renv.lock`, call
159+
[`renv::snapshot()`](https://rstudio.github.io/renv/reference/snapshot.html).
156160

157161
**Whenever you update packages on your development machine, you should
158-
run `renv::snapshot()` command again to make sure the packages used on
159-
GitHub stay in sync.**
162+
run
163+
[`renv::snapshot()`](https://rstudio.github.io/renv/reference/snapshot.html)
164+
command again to make sure the packages used on GitHub stay in sync.**
160165

161166
To learn more about [renv](https://rstudio.github.io/renv/), please see
162167
their [Introduction to

articles/use-package.html

Lines changed: 45 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

articles/use-package.md

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,48 @@ on your shiny application object directly. Unfortunately, the test file
149149
will not be able to be saved. Instead, the test commands can be copied
150150
into a test script manually.
151151

152+
## Running Applications with a function
153+
154+
Some packages, such as [golem](https://thinkr-open.github.io/golem/),
155+
provide a function that runs or returns a shiny application. In this
156+
case, you can create a wrapper function to perform two actions: load the
157+
package and return an app. For example, if your package is named `mypkg`
158+
and the function that runs the app is `run_test_app()`, you can create a
159+
wrapper function like this:
160+
161+
``` r
162+
run_mypkg_app <- function() {
163+
library(mypkg)
164+
run_test_app()
165+
}
166+
167+
app <- AppDriver$new(run_mypkg_app, name = "mypkg-app")
168+
```
169+
170+
For shorthand, you can also use the package function directly:
171+
172+
``` r
173+
app <- AppDriver$new(run_test_app, name = "mypkg-app")
174+
```
175+
176+
When using a function to initialize the `AppDriver`,
177+
[shinytest2](https://rstudio.github.io/shinytest2/) will automatically
178+
call
179+
[`pkgload::load_all()`](https://pkgload.r-lib.org/reference/load_all.html)
180+
when you execute `library(<pkg>)` or `require(<pkg>)` to load your dev
181+
package, `<pkg>`, in the background R process. Similar to
182+
[mirai](https://mirai.r-lib.org), there is no carryover to the execution
183+
within the background R process. All packages may need to be
184+
[`library()`](https://rdrr.io/r/base/library.html)’ed again.
185+
186+
[golem](https://thinkr-open.github.io/golem/) provides a template
187+
`run_app()` function. [golem](https://thinkr-open.github.io/golem/) app
188+
authors can use the shorthand:
189+
190+
``` r
191+
app <- AppDriver$new(run_app)
192+
```
193+
152194
## Other setup steps
153195

154196
There are a few steps that are needed for both types of tests.
@@ -164,24 +206,27 @@ to the `Suggests` section in your `DESCRIPTION` file.
164206
shinytest2
165207

166208
When all of these items are in place, you can test your package using
167-
`devtools::install(); testthat::test_local()` or by running
168-
`R CMD check` on your package. If you are using the RStudio IDE, you can
169-
also run Build -\> Test Package or Build -\> Check Package.
209+
[`testthat::test_local()`](https://testthat.r-lib.org/reference/test_package.html)
210+
or by running `R CMD check` on your package. If you are using the
211+
RStudio IDE, you can also run Build -\> Test Package or Build -\> Check
212+
Package.
170213

171-
[shinytest2](https://rstudio.github.io/shinytest2/) requires that your
172-
package to be *installed* when testing.
214+
[shinytest2](https://rstudio.github.io/shinytest2/) **no longer**
215+
requires that your package to be *installed* when testing. It will load
216+
from your local path.
173217
[`testthat::test_local()`](https://testthat.r-lib.org/reference/test_package.html)
174218
(and related wrappers) eventually call
175219
[`pkgload::load_all()`](https://pkgload.r-lib.org/reference/load_all.html)
176-
to temporarily source the local R package. You can use
177-
[`test_local()`](https://testthat.r-lib.org/reference/test_package.html)
178-
to test non-[shinytest2](https://rstudio.github.io/shinytest2/) tests,
179-
but you will need to install your R package to safely execute your
180-
[shinytest2](https://rstudio.github.io/shinytest2/) tests. If not
181-
installed, it will create a confusing situation where your
182-
[shinytest2](https://rstudio.github.io/shinytest2/) tests are running on
183-
a *different* version of your R package (whichever was last installed),
184-
than the rest of your tests (the current source).
220+
to temporarily source the local R package in the foreground for unit
221+
testing. [shinytest2](https://rstudio.github.io/shinytest2/) has made
222+
the stance that App authors **must** call `library(<pkg>)` or
223+
`require(<pkg>)` on their package within their App. This ensures that
224+
the package is loaded in the background R process that runs the Shiny
225+
application. When `library*()` is called,
226+
[shinytest2](https://rstudio.github.io/shinytest2/) will automatically
227+
execute
228+
[`pkgload::load_all()`](https://pkgload.r-lib.org/reference/load_all.html)
229+
to load the package’s source code.
185230

186231
## How should I test multiple applications?
187232

news/index.html

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)