deephaven / deephaven-plugins

Deephaven Plugins
11 stars 15 forks source link

feat: Column sources for ui.table formatting #1010

Closed mattrunyon closed 1 week ago

mattrunyon commented 2 weeks ago

Fixes #984

Allows all string format values to instead specify a column as the source. Ensures the column is always fetched and throws if the column is not a string type (can cause some really bad performance issues if value formatting is invalid). Also modified to just resolve all theme colors since this change could lead to unresolved theme colors in a column source.

The example in the docs or this example shows the feature working. Change the String cast on line 6 to non-string to test the error is thrown and displayed.

This example uses an input table joined to the table so you can adjust the formatting colors via input table (something Raffi asked about specifically)

from deephaven import input_table
from deephaven import ui
import deephaven.plot.express as dx

_stocks = dx.data.stocks()
_source = _stocks.select_distinct("Sym").update("Color=(String)null")

color_source = input_table(init_table=_source, key_cols="Sym")

t = ui.table(
    _stocks.natural_join(color_source, "Sym", "SymColor=Color"),
    hidden_columns=["SymColor"],
    format_=[
        ui.TableFormat(cols="Sym", background_color="SymColor")
    ],
)