Skip to content

Commit

Permalink
Set RNG seed for htmlwidgets IDs (r-lib#2294)
Browse files Browse the repository at this point in the history
`htmlwidgets::setWidgetIdSeed()` needs to be explicitly called for this due to how `htmlwidgets:::createWidgetId()` works
  • Loading branch information
salim-b authored and SebKrantz committed Jun 1, 2024
1 parent 6d5478a commit f93c6db
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Remove redundant entries in the documentation index when multiple explicit `@usage` tags are provided (@klmr, #2302)
* The article index now sorts vignettes and non-vignette articles alphabetically by their filename (literally, their `basename()`), by default (@jennybc, #2253).
* Add Catalan translation (@jmaspons, #2333)
* Set RNG seed for htmlwidgets IDs. This reduces noise in pkgdown reference HTML output when examples generate htmlwidgets (@salim-b, #2294).

# pkgdown 2.0.7

Expand Down
7 changes: 5 additions & 2 deletions R/build-reference.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@
#' rapidly prototype. It is set to `FALSE` by [build_site()].
#' @param run_dont_run Run examples that are surrounded in \\dontrun?
#' @param examples Run examples?
#' @param seed Seed used to initialize so that random examples are
#' reproducible.
#' @param seed Seed used to initialize random number generation so that
#' examples are reproducible.
#' @param devel Determines how code is loaded in order to run examples.
#' If `TRUE` (the default), assumes you are in a live development
#' environment, and loads source package with [pkgload::load_all()].
Expand Down Expand Up @@ -223,6 +223,9 @@ examples_env <- function(pkg, seed = 1014, devel = TRUE, envir = parent.frame())
width <- purrr::pluck(pkg, "meta", "code", "width", .default = 80)
withr::local_options(width = width, .local_envir = envir)
withr::local_seed(seed)
if (requireNamespace("htmlwidgets", quietly = TRUE)) {
htmlwidgets::setWidgetIdSeed(seed)
}

examples_env <- child_env(globalenv())
if (file_exists(pre_path)) {
Expand Down
4 changes: 2 additions & 2 deletions man/build_reference.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/build_site.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vignettes/test/widgets.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Test spacing above widget.

```{r, echo=FALSE}
# set seed for reproducible widget id
if (requireNamespace("htmltools", quietly = TRUE)) {
if (requireNamespace("htmlwidgets", quietly = TRUE)) {
htmlwidgets::setWidgetIdSeed(42)
}
Expand Down

0 comments on commit f93c6db

Please sign in to comment.