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

Abierto
#5,617 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
javascript, python

Línea de trabajo

Ejecuta primero el reproductor proporcionado de Python y Playwright, comparando el renderizado inicial con la ruta posterior de Plotly.restyle. Rastrea cómo se gestiona table cells.format durante el renderizado inicial frente a restyle, y considera el issue terminado cuando los valores de celda de tipo cadena se rendericen de forma idéntica en ambos casos.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
18.8k
Forks
2.8k
Merge medio
16 h 26 min
PR fusionados (30 d)
21

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de plotly/plotly.py

Todos los issues de plotly/plotly.py

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.