-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plots: document html template (#2472)
* user guide: add custom plots html guide * plots/config: add entries for html_tempalte * ref: fix broken links in plots * Edited the guide for clarity * Minor edits * link and filename update * modified for non-http-server introduction * moved the information to `/doc/command-reference/plots/` * moved the example to the bottom. some minor fixes. * minor changes in the example * removed the ug document * ref: copy edits to HTML plot templates info. * Restyled by prettier (#2588) Co-authored-by: Restyled.io <[email protected]> * minor changes after review * Modified description to be more general. * ref: copy edits to plots HTML templates * Restyled by prettier (#2629) Co-authored-by: Restyled.io <[email protected]> * ref: copy edits to plots HTML template example * Restyled by prettier (#2630) Co-authored-by: Restyled.io <[email protected]> * minor modifications in filenames Co-authored-by: Jorge Orpinel <[email protected]> Co-authored-by: Emre Sahin <[email protected]> Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io <[email protected]>
- Loading branch information
1 parent
e0bd5a7
commit 63e0c00
Showing
4 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,20 @@ header (first row) are equivalent to field names. | |
|
||
- `<DVC_METRIC_Y_LABEL>` (optional) - field name to display as the X axis label | ||
|
||
## HTML templates | ||
|
||
It's possible to supply an HTML file to `dvc plot show` and `dvc plot diff` by | ||
using the the `--html-template` option. This allows you to customize the | ||
container where DVC will inject plots it generates. | ||
|
||
> ⚠️ This is a separate feature from | ||
> [custom Vega templates](/doc/command-reference/plots#custom-templates). | ||
The only requirement for this HTML file is to specify the place to inject plots | ||
with a `{plot_divs}` marker. See an | ||
[example](/doc/command-reference/plots#example-offline-html-template) that uses | ||
this feature to render DVC plots without an Internet connection, below. | ||
|
||
## Options | ||
|
||
- `-h`, `--help` - prints the usage/help message, and exit. | ||
|
@@ -260,3 +274,53 @@ file:///Users/usr/src/plots/classes.csv.html | |
|
||
> A confusion matrix [template](/doc/command-reference/plots#plot-templates) is | ||
> predefined in DVC (found in `.dvc/plots/confusion.json`). | ||
### Example: Offline HTML Template | ||
|
||
The plots generated by `dvc plots` uses Vega JavaScript libraries, and by | ||
default these load [online resources](https://vega.github.io/vega/usage/#embed). | ||
There may be times when you need to produce plots without Internet access, or | ||
want to customize the plots output to put some extra content, like banners or | ||
extra text. DVC allows to replace the HTML file that contains the final plots. | ||
|
||
Download the Vega libraries into the directory where you'll produce the | ||
`dvc plots`: | ||
|
||
```dvc | ||
$ wget https://cdn.jsdelivr.net/npm/[email protected] -O my_vega.js | ||
$ wget https://cdn.jsdelivr.net/npm/[email protected] -O my_vega_lite.js | ||
$ wget https://cdn.jsdelivr.net/npm/[email protected] -O my_vega_embed.js | ||
``` | ||
|
||
Create the following HTML file and save it in `.dvc/plots/mypage.html`: | ||
|
||
```html | ||
<html> | ||
<head> | ||
<script src="my_vega.js" type="text/javascript"></script> | ||
<script src="my_vega_lite.js" type="text/javascript"></script> | ||
<script src="my_vega_embed.js" type="text/javascript"></script> | ||
</head> | ||
<body> | ||
{plot_divs} | ||
</body> | ||
</html> | ||
``` | ||
|
||
Note that this is a standard HTML file with only `{plot_divs}` as a placeholder | ||
for DVC to inject plots. `<script>` tags in this file point to the local | ||
JavaScript libraries we downloaded above. We can use it like this: | ||
|
||
```dvc | ||
$ dvc plots show --html-template .dvc/plots/mypage.html | ||
``` | ||
|
||
You can also make it the default HTML template by setting it as `dvc config` | ||
parameter `plots.html_template`. | ||
|
||
```dvc | ||
$ dvc config plots.html_template plots/mypage.html | ||
``` | ||
|
||
Note that the path supplied to `dvc config plots.html_template` is relative to | ||
`.dvc/` directory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters