plotly / plotly/plotly.js

Bug: Exporting as HTML (New Issues as of v.3.0.1)

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

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

bug P2
主要言語
JavaScript
スター
18.3k
フォーク
2k
平均マージ
2日 12時間
マージ済み PR(30日)
28

説明

Hey, I have been using plotly.js within my react application for several months now.
I never noticed this issue before but my users have started to report the following issue as of today, and I wonder if its linked to the latest release of plotlyjs.

In my React app I'm using a combination of react plotly and plotlyjs for various bits of functionality.

The key bit thats relevant here, is exporting charts as HTML.

Since the js client has no .to_html method like the python client does, I had to do this with a bit of a workaround as suggested by other people online.

// Function to export as HTML
    const exportAsHTML = (chartData: ChartData, fileName: string) => {
        const plotlyScript = `
        <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
        <style>
            body, html {
                margin: 0;
                padding: 0;
                width: 100%;
                height: 100%;
                overflow: hidden;
            }
            #plotly-chart {
                width: 100%;
                height: 100%;
            }
        </style>
        <div id="plotly-chart"></div>
        <script>
            var data = ${JSON.stringify(chartData.data)};
            var layout = ${JSON.stringify(chartData.layout)};
            Plotly.newPlot('plotly-chart', data, layout);
        </script>
        `;
        const blob = new Blob([plotlyScript], { type: 'text/html' });
        const url = URL.createObjectURL(blob);
        const link = document.createElement('a');
        link.href = url;
        link.download = fileName;
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        URL.revokeObjectURL(url);
    };

Basically I'm creating the HTML skeleton myself and passing in the chart data / layout to be read by the embedded plotly client.

Here i'm explicitly importing the latest version of plotlyjs via the <script/> tag

Now as for the results. The html version of the chart is either missing data entirely, or the data has been mutated such that it doesn't match the original chart.

A couple of examples are below.


EXAMPLE A

This chart (plotted using React Plotly)

Image

Becomes the following (missing data entirely)

Image


EXAMPLE B

This chart (plotted using React Plotly)

Image

Becomes the following (shape of data changed drastically)

Image


Obviously this is a major issue and if not fixed could mislead our data analysts.

The only solution i can think of for now is to create a python backend endpoint to take the chart data and layout and use the python libraries to_html function to send back the html, but this seems unnecessarily convoluted.

Now, it could be that I have been taking the wrong approach the whole time, but I'd be surprised if this was the case since the feature has been live for months and has only now been reported as buggy. Hence why I suspect its to do with the latest release (21 hours ago as of writing this)

As a sidenote, why on earth isn't there a built in .to_html method in the javascript client library? The disparity between this and the python library is confusing.

Any guidance is appreciated.

Best,
Pat

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供されたexportAsHTML関数、影響を受けるグラフデータとレイアウト、およびCDNから読み込まれる最新のPlotlyクライアントを使って問題を再現します。元のReact PlotlyグラフとダウンロードしたHTML出力を比較し、エクスポート中またはレンダリング中にデータが失われているか、変更されているかを切り分けます。エクスポートされたHTMLがグラフのデータと形状を保持していれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, react
領域
data-visualization, frontend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
説明が足りない
初心者へのやさしさ
38/100

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

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