DVC Render
dvc-render is a Python library for rendering data stored in DVC plots format into various output formats, such as Vega. It also supports generating HTML and Markdown reports containing multiple plots. It is used internally by DVC, DVCLive, and DVC Studio. The current version is 1.0.2, with frequent patch and minor releases.
Warnings
- breaking The 1.0.0 release standardized `plots` across DVC, Studio, and VS Code. Users with custom plot configurations defined for DVC versions prior to 1.0.0 may experience breaking changes or require updates to their `dvc.yaml` definitions.
- gotcha Using custom plot templates can be complex. Earlier versions (0.5.x, 0.7.0) had multiple fixes related to correctly parsing recursive dictionary structures, handling lists, and finding data anchors within custom templates. Ensure your custom templates strictly adhere to DVC's expected `dvc plots` schema to avoid rendering issues.
- gotcha dvc-render is designed to work with data in 'DVC plots format'. While the library can be used independently, its full utility and intended use cases are deeply integrated with the DVC ecosystem. Users expecting a generic, standalone plotting library might find it less flexible without the context of a DVC project.
Install
-
pip install dvc-render
Imports
- VegaRenderer
from dvc_render import VegaRenderer
- render_html
from dvc_render import render_html
Quickstart
from dvc_render import VegaRenderer, render_html
properties = {"template": "confusion", "x": "predicted", "y": "actual"}
datapoints = [
{"predicted": "B", "actual": "A"},
{"predicted": "A", "actual": "A"},
{"predicted": "B", "actual": "B"},
]
# Create a renderer for a single plot
renderer = VegaRenderer(datapoints, "my_confusion_plot", **properties)
# Get the Vega-Lite JSON specification
plot_content = renderer.get_filled_template()
print("Generated Vega-Lite:", plot_content[:100], "...") # Print first 100 chars
# Generate an HTML report with the plot
render_html([renderer], "report.html")
print("Generated report.html")