Skip to content

Commit

Permalink
Set seed for htmlwidgets IDs
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 committed Oct 17, 2023
1 parent 6638331 commit 4e0809b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
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 4e0809b

Please sign in to comment.