[BUG] Graphs excluded from print pages if they have over 1000 datapoints
Maintainer antworten meist innerhalb von 2 Tagen
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- plotly, python
- Bereich
- data-visualization, frontend
Rechercherichtung
Beginne mit der bereitgestellten Beispiel-App und variiere num_points um 1000 herum. Reproduziere anschließend das Drucken über den Browserdruck und html2pdf in Chrome, Edge und Firefox. Untersuche das Rendering von dcc.Graph und die Einrichtung von assets/html2pdf. Als abgeschlossen gilt die Aufgabe, wenn der Graph in der Druckausgabe für mehr als 1000 Punkte sichtbar bleibt und korrekt skaliert wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Context
When saving a Dash app as a pdf dcc.Graph behaves wonky if the graph contains more than 1000 datapoints (starting at 1001 points). The actual graph doesn't appear properly in the printed page. Instead, an empty graph is shown (or it could be that the background is printed over the graph).
I tested the behavior in Firefox, Chrome and Edge, and the behavior is different per browser. I tested both printing the page via the browser print page functionality and via the html2pdf library.
In Chrome and Edge, the browser print page functionality works fine with more than 1000 datapoints. In Firefox, the datapoints are gone, and the print preview shows an empty plot.
Using the html2pdf library, all browser have issues. In Chrome and Edge, the plot line seems to have a different scale and is hidden behind the plot background. In Firefox the plot line is completely gone, just showing an empty plot. It could be that it is hidden behind the plot background as well but that the scale is smaller so we don't see it.
It's possibly a bit of an edge case that might not be due to Dash. If it is not, please consider documenting this limitation somewhere.
Expected behavior
The plot should be visible on the printed page regardless how many points are in the plot.
Example app
To reproduce the behavior, take this example app for generating a simple plot and play around with num_points.
import dash
from dash import dcc, html, clientside_callback, Input
import plotly.express as px
import numpy as np
app = dash.Dash(__name__)
num_points = 2000
x = np.linspace(0, 10, num_points)
y = np.sin(x) * 100 + np.random.normal(0, 5, num_points)
fig = px.line(
x=x,
y=y,
title="Line Chart",
)
app.layout = html.Div(
id="main_container",
children=[
html.H1("Plotly Dash App"),
dcc.Graph(figure=fig),
html.Div(
children=[
dcc.Button(
id="save_as_pdf",
children="Save as PDF",
)
],
),
]
)
clientside_callback(
f"""
function (button_clicked) {{
if (button_clicked && button_clicked > 0) {{
var mainContainerElement = document.getElementById("main_container");
var opt = {{
// margin units are those that are defined in jsPDF key below.
margin: 10,
filename: 'test_file.pdf',
image: {{ type: 'jpeg', quality: 0.98 }},
html2canvas: {{
scale: 3,
width: 1920,
dpi: 300,
}},
jsPDF: {{ unit: 'mm', format: 'A4', orientation: 'p' }},
// pagebreak: {{ mode: ['avoid-all'] }}
}};
html2pdf().from(mainContainerElement).set(opt).save();
}}
}}
""",
Input(component_id="save_as_pdf", component_property="n_clicks"),
)
if __name__ == "__main__":
app.run(debug=True)
Setup
dash 4.0.0
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-table 5.0.0
plotly 6.5.2
numpy 2.4.4
Take html2pdf from here: https://github.com/eKoopmans/html2pdf.js/blob/main/dist/html2pdf.bundle.min.js and put it in the assets folder next to the example app.
-
Browser, Version and OS
- OS: Windows
- Browser:
- Chrome: 150.0.7871.114
- Firefox: 152.0.4
- Edge: 150.0.4078.48
Screenshots
Edge/Chrome with 2000 points
Print page (this is also how it shows in all cases when number of points <= 1000)
html2pdf
Firefox with 2000 points
Print page
html2pdf
- Vorherrschende Sprache
- Python
- Sterne
- 24.4k
- Forks
- 2.3k
- Ø Merge
- 2 T. 14 Std.
- Gemergte PRs (30 T.)
- 23
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus plotly/dash
-
P2 plotly-internal size: 1 task
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 2 Tagen
-
Extract graph schema validation into properly named testEvtl. vergeben @Nice6042 hat das vor 58 Tagen übernommen. Offengood first issue P3 size: 1 task
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
plotly/dash#3735 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
-
[BUG] dcc.Dropdown: hidden focus-target input is focusable inside aria-hidden and can overflow its wrapperEvtl. vergeben @KoolADE85 hat das vor 6 Tagen übernommen. Offenbug P2 size: 1
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 56/100
plotly/dash#4042 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 2 Tagen
-
P3 plotly-internal size: 10+ task
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 30/100
plotly/dash#4040 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Drop Python 3.9 SupportOffenP2 plotly-internal size: 5 task
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
plotly/dash#4038 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
Ähnliche Issues
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 83/100
PedestrianDynamics/pyFDS-Evac#766 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 91/100
alchaincyf/nuwa-skill#86 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 2 Tagen
-
Docs Needs Triage
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
pandas-dev/pandas#71055 ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug]: graphify reads files that git's global ignore file hidesEvtl. vergeben @smngvlkz hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Graphify-Labs/graphify#4335 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag