plotly / plotly/plotly.R

HTML documents including plotly plots are not reproducible

オープン
#2,074 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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. リポジトリをフォークし、ブランチを切って変更します。
  4. 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
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。