Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[BUG]: Table string cells render as NaN when cells.format is set before initial render, but Plotly.restyle renders correctly

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

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
javascript, python

调研方向

首先运行提供的 Python 和 Playwright 复现程序,将初始渲染与后续的 Plotly.restyle 路径进行比较。跟踪初始渲染与 restyle 过程中如何处理 table cells.format,并在字符串单元格值在两种情况下的渲染结果完全一致时,认为该 issue 已完成。

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

描述

bug good for agent P3 size: 3
Description

When initializing a Plotly go.Table with string cell values such as
"rgb(239, 243, 255)" and setting cells.format=[1] before the first render, the
string values are displayed as NaN.

However, if the same base table is rendered first and the same cells.format value
is then applied dynamically through Plotly.restyle, the table displays the original
string values correctly.

The setting is accepted by plotly.py and stored on the trace object, so this looks
like an initial-render formatting/coercion discrepancy in table traces rather than an
invalid Python-side property assignment.

Screenshots/Video
Image Image
Steps to reproduce
import io

import plotly
import plotly.graph_objects as go
import plotly.io as pio
from PIL import Image, ImageChops
from playwright.sync_api import sync_playwright


print(f"Plotly version: {plotly.__version__}")

fig = go.Figure(
    go.Table(
        header={"values": ["Color"]},
        cells={"values": [["rgb(239, 243, 255)", "rgb(8, 81, 156)"]]},
    )
)

# Screenshot 1 / plot1.png: set cells.format in Python before the initial render.
fig.data[0].cells.format = [1]
assert fig.data[0].cells.format == (1,)
print("Python-side cells.format:", fig.data[0].cells.format)
html1 = pio.to_html(fig, full_html=True, include_plotlyjs="cdn")

# Screenshot 2 / plot2.png: render first, then apply the same value with JS.
fig.data[0].cells.format = None
html2 = pio.to_html(fig, full_html=True, include_plotlyjs="cdn")
html2 = html2.replace(
    "</body>",
    """
<script>
window.addEventListener("DOMContentLoaded", () => {
    const plotEl = document.getElementsByClassName("plotly-graph-div")[0];
    setTimeout(() => {
        Plotly.restyle(plotEl, {"cells.format": [1]}, [0]);
    }, 1000);
});
</script>
</body>""",
)

with sync_playwright() as playwright:
    browser = playwright.chromium.launch(
        headless=True,
        args=["--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu"],
    )
    page = browser.new_page(viewport={"width": 1200, "height": 800})

    page.set_content(html1)
    page.wait_for_timeout(1500)
    img1 = page.screenshot(path="plot1.png")

    page.set_content(html2)
    page.wait_for_timeout(2000)
    img2 = page.screenshot(path="plot2.png")

    browser.close()

diff = ImageChops.difference(
    Image.open(io.BytesIO(img1)).convert("RGB"),
    Image.open(io.BytesIO(img2)).convert("RGB"),
)

print("Saved plot1.png and plot2.png")
assert diff.getbbox() is not None, "Reproducer did not reproduce: images are identical."
Notes

Add info here that doesn't fit in the other sections.

主要语言
Python
星标
18.8k
派生
2.8k
平均合并
13 小时 41 分钟
30 天内合并 PR
21

贡献指南

打开贡献指南

从这里开始

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

plotly/plotly.py 的其他 Issue

查看 plotly/plotly.py 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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