Convert tables to HTML strings
The to_html function in the deephaven.html module converts a Deephaven table to a string that contains an HTML table. It is the module's only function. This is handy when you want to drop a small table into an email, a report, or any other page that renders HTML.
Convert a table to an HTML string
Pass the table to convert as the only argument. Let's create a simple table and convert it to HTML. The Letter column includes a value that contains a comma and a null value, so the output shows how to_html writes them.
The returned string is an HTML <table> element with a header row of column names and one row for each table row. to_html writes each cell's value as untyped text, so the output carries no column type information. It writes values as follows:
- It escapes string values with CSV rules, not HTML rules. It wraps a value that contains a comma, a double quote, or a line break in double quotes and doubles any double quotes inside it. It writes characters such as
<and&as-is. Because string values aren't HTML-escaped, a value that contains HTML markup becomes active markup in any page that displays the output. Convert only tables whose contents you trust, or HTML-escape untrusted string values before you convert the table. - It formats
Instantvalues, such as theDatetimecolumn created withdatetime_col, in the server JVM's system default time zone, which can differ from the time zone the web UI uses to display the table. - It writes null values as
(null). - It writes other values, including other date-time types such as
ZonedDateTimeandLocalDate, with their JavatoStringform. For a Java array column, such as anint[]column, that form is an object reference like[I@1b6d3586, not the array's contents.
In this example's output, the B, C value is wrapped in double quotes, the null value is written as (null), and the Datetime values are in the server's time zone (UTC here), while the table widget shows them in the web UI's time zone.
The string is a copy of the table's rows at the moment you call to_html. If the table is ticking, the string doesn't change as the table updates. Call to_html again to get the latest rows.
Warning
to_html builds the whole table into a single in-memory string, so use it only on small tables to avoid running out of memory.