plotly / plotly/plotly.R

HTML documents including plotly plots are not reproducible

未关闭
#2,074 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

I believe it is known that the value of plotly::plot_ly(x = 1, y = 1)$x$cur_data is hard to reproduce, compare https://github.com/plotly/plotly.R/issues/1048. Some work has been done in #1379 towards use in shinytest at least.

I am also using shinytest, but in my app, users are downloading HTML files with plotly plots generated using rmarkdown::render(). So these files are still non-reproducible because I cannot seem to use renderPlotly() inside rmarkdown::render(). To see the problem:

bug.Rmd:

---
output: html_document
---

```{r}
plotly::plot_ly(x = 1, y = 1)
```

Then run R -q -s -e 'rmarkdown::render("bug.Rmd")' and see the value of cur_data in bug.html change every time you regenerate it.

I see two options:

  • I could replicate the logic of
    https://github.com/plotly/plotly.R/blob/bab01af316673e35d8314129178bfb27eed27fe7/R/shiny.R#L46-L53
    inside bug.Rmd, like this:
    p <- plotly::plot_ly(x = 1, y = 1)
    p$x$attrs <- NULL # and a few more
    p
    
    However, this breaks the plot. Any way I can make this work?
  • I have also tried putting this inside bug.Rmd:
    shiny::snapshotPreprocessOutput(
      plotly::plot_ly(x = 1, y = 1),
      function(value) {
        # https://github.com/plotly/plotly.R/blob/3d49fbc5897703d58b/R/shiny.R#L68
        json <- jsonlite::from_JSON(value)
        json$x <- json$x[setdiff(names(json$x), c("visdat", "cur_data", "attrs"))]
        # https://github.com/plotly/plotly.R/blob/3d49fbc589/R/utils.R#L1020-L1025
        jsonlite::toJSON(json,
          digits = 50, auto_unbox = TRUE, force = TRUE,
          null = "null", na = "null", time_format = "%Y-%m-%d %H:%M:%OS6"
        )
      }
    )
    
    but rmarkdown::render() seemed to ignore it, even inside shinytest (or did I do anything wrong there)?
  • One could amend #1365 to take into account a hash of the current plot serialization to avoid generating identical IDs even if the external seed is reset to the same values externally. This would avoid the need for tempfile().

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用 bug.Rmd 和 R -q -s -e 'rmarkdown::render("bug.Rmd")' 重现该问题,然后比较多次渲染过程中 bug.html 中的 cur_data 值。阅读 R/shiny.R 和 R/utils.R 中引用的逻辑,以及相关 issue #1048、#1379 和 #1365。完成的标准是:使用 rmarkdown::render() 渲染的 HTML 文档能够生成可复现的绘图数据,同时不会破坏绘图。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, r
领域
data-visualization, web-dev
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。