-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set RNG seed for htmlwidgets IDs #2294
Conversation
Could you please give me a PR without the other cosmetic changes? And with add a news bullet 😄 |
`htmlwidgets::setWidgetIdSeed()` needs to be explicitly called for this due to how `htmlwidgets:::createWidgetId()` works
95c5315
to
4e0809b
Compare
@hadley I've updated the PR accordingly. |
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we drop this block now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. The htmlwidgets seed init in R/build-reference.R
above only applies to htmlwidgets that are generated in examples (built by build_reference()
), not vignettes/articles (built by build_articles()
). Currently, only the former function offers a seed
param.
I think we need to modify the envir
passed to rmarkdown::render()
if we also want to have stable htmlwidget IDs for articles by default:
Line 22 in 8af84b7
envir = globalenv(), |
Should I give it a try? If yes, in a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let's do that in a separate PR. I'll merge this one momentarily. Thanks for working on this!
`htmlwidgets::setWidgetIdSeed()` needs to be explicitly called for this due to how `htmlwidgets:::createWidgetId()` works
htmlwidgets::setWidgetIdSeed()
needs to be explicitly called for stable htmlwidget IDs due to howhtmlwidgets:::createWidgetId()
works.This reduces noise in pkgdown reference HTML output when examples generate htmlwidgets. Note that this change makes only the
id
attribute of the outer<div>
container of an htmlwidget stable, and not its content, which could still remain irreproducible due to other reasons (this is e.g. the case for plotly charts).The second commit in this PR contains cosmetic changes which are unrelated to PR's goal.