The Report Generator node can generate a text (e.g. HTML) report with the data it receives. The report can be customized with a template in Tera (Jinja2) format.
Each input must be configured with its own template. Then the Root Template is used to consolidate the individual reports into a single report.
The node has the following configuration options:
input_reports variable.payload variable. For example, {{ payload[0].name }} would access the name field of the first record.Inputs are expected to be in the serde-json::Value format. Since many data operations use Apache Arrow RecordBatch, the RecordBatch can be converted to serde-json::Value using a Data Stream to JSON node.
The base template for the report, used to consolidate the individual input reports into a single document.
<h1>Report</h1>
{% for input_id, reporter in input_reports %}
<h1>Input: {{input_id}}</h1>
{% for report in reporter %}
{{ report }}
{% endfor %}
{% endfor %}
The Root template can be a full HTML document. For example:
<!DOCTYPE html>
<html>
<head>
<style>
table { width: 100%; }
</style>
</head>
<body>
<h1>Report</h1>
{% for input_id, reporter in input_reports %}
<h1>Input: {{input_id}}</h1>
{% for report in reporter %}
{{ report }}
{% endfor %}
{% endfor %}
</body>
</html>
The template for each input. This is where the data from the input is rendered. The input template can access the input data using the payload variable. For example, {{ payload[0].name }} would access the name field of the first record.
<h2>Input Report</h2>
<table>
{% for row in payload %}
{# If this is the first row, print the header first #}
{% if loop.first %}
<tr>
{% for key,value in row %}
<th>{{key}}</th>
{% endfor %}
</tr>
{% endif %}
<tr>
{% for key,value in row %}
<td>{{value}}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
The node generates text. It could be used to generate other text formats, such as JSON or CSV.
For example, to generate a JSON document:
{
"report": [
{% for input_id, reporter in input_reports %}
{
"input_id": "{{input_id}}",
"reports": [
{% for report in reporter %}
{{ report }},
{% endfor %}
]
},
{% endfor %}
]
}
Report Generator can render SVG inputs natively. By combining with the Plotter Node, you can generate charts and graphs in the report.
Another way to create custom multimedia is to use the Data Stream to JSON node to convert the data to JSON and then use a custom HTML template to render the multimedia or charts.