Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use_table_size hook #911

Open
jnumainville opened this issue Sep 25, 2024 · 0 comments
Open

use_table_size hook #911

jnumainville opened this issue Sep 25, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@jnumainville
Copy link
Collaborator

Currently, it's a little tricky to figure out the size of a table and keep it in sync if it ties to something that needs to be displayed. For example, this code checks if a partitioned table has the partitions to ensure that it will render the plot correctly.

import deephaven.plot.express as dx
import deephaven.ui as ui
from deephaven import empty_table, time_table
from random import choice

def rand_type() -> str:
    return choice(["Sine", "Cosine"])

tt = time_table("PT0.25s").update([
    "Type = rand_type()",
    "X = 0.05 * i",
    "Y = (Type == `Sine`) ? sin(X) : cos(X)"
])

pt = tt.partition_by("Type")

@ui.component
def plot_pt(partitioned_table, initial_val):
    text, set_text = ui.use_state(initial_val)
    data = ui.use_table_data(partitioned_table.table)

    ct = ui.use_memo(
        lambda: partitioned_table.get_constituent(text.capitalize()) if text != "" else None,
        [partitioned_table, text, data]
    )
    return [
        ui.text_field(value=text, on_change=set_text),
        dx.line(
            ct, x="X", y="Y", title=f"Partition Key: {text}"
        )
        if ct != None else ui.text("Please enter a valid partition.")
    ]

p = plot_pt(pt, "Sine")

This is not great with a large table since it would be pulling out a lot of data. Of course if this was adding and removing rows you might have to do something like this anyways, but regardless, there could be cases where you want to see the size of the table and we don't have a good way of keeping that in sync without using use_table_listener or a hook built on top of that (use_table_data in this case)

@jnumainville jnumainville added enhancement New feature or request triage labels Sep 25, 2024
@vbabich vbabich added this to the October 2024 milestone Oct 1, 2024
@vbabich vbabich removed the triage label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants