-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.py
42 lines (31 loc) · 1.05 KB
/
render.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import base64
import os
from pandas.core import base
import plotly.express as px
from pdf_reports import pug_to_html, write_report, preload_stylesheet
rows = [
["time", "event", "subevent","text", "room"],
["time", "event", "subevent","text", "room"],
["time", "event", "subevent","text", "room"],
["time", "event", "subevent","text", "room"],
]
def main():
params = {
"table_rows": rows
}
current_dir = os.path.dirname(os.path.abspath(__file__))
params["workdir"] = f"file:///{current_dir}"
df = px.data.tips()
fig = px.pie(df, values='tip', names='day')
# fig.show()
fig_as_bytes = bytes(fig.to_image(format="png"))
fig_as_b64 = base64.b64encode(fig_as_bytes)
params["fig_as_b64"] = fig_as_b64.decode("utf-8")
# css = preload_stylesheet('style.css')
html = pug_to_html("template.pug", title=" Report", **params)
# , extra_stylesheets=[css])
write_report(html, "example.pdf")
with open("report.html", "w") as out:
out.write(html)
if __name__ == "__main__":
main()