Skip to content
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

Avoid using tempfile() for ID #1365

Closed
wants to merge 1 commit into from
Closed

Avoid using tempfile() for ID #1365

wants to merge 1 commit into from

Conversation

krlmlr
Copy link

@krlmlr krlmlr commented Oct 10, 2018

This changes new_id() to use runif() and digest::digest() to generate reproducible IDs. This is important for testing and resolves rstudio/shinytest#174 and #985 (comment).

@cpsievert cpsievert self-requested a review October 29, 2018 19:45
@cpsievert
Copy link
Collaborator

Thanks for the PR @krlmlr! Although it's definitely a corner-case, this change would break cases where one has (probably inadvertently) reset the same seed in-between adding of new layers.

set.seed(1)
p <- plot_ly()
set.seed(1)
p <- add_markers(p, data = mtcars[1:10, ], x = ~wt, y = ~mpg, color = I("black"))
set.seed(1)
add_paths(p, data = mtcars[11:20, ], x = ~wt, y = ~mpg, color = I("black"))

The reasons have to do with the way plotly works internally -- it uses new_id() to attach an ID to each graphical layer and it's currently not smart enough to deal with non-unique IDs.

I'll contact @wch and see if we can't add some special logic in shinytest to provide a better experience plotly+shinytest experience without such a fundamental change to plotly

@wch
Copy link
Collaborator

wch commented Oct 29, 2018

FYI: it's possible to call snapshotPreprocessOutput() to add an output preprocessing function to clean up the raw output value to something that's more deterministic for testing. See:
https://github.com/rstudio/shiny/blob/6ede019/R/snapshot.R#L10-L19

For an example of usage, see: https://github.com/rstudio/DT/blob/80981d3/R/shiny.R#L116-L124

@cpsievert
Copy link
Collaborator

Closing in favor of #1379

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

difference between expected and current when using plotly (elementId)
3 participants