Updating DataTable data #3328
-
Dear all, I want to use a DataTable to View data that changes rapidly.
Thank You! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
There's a couple of things that are an issue in the code you post above. First off, you wouldn't use Second: you're trying to perform a CSS type query on a widget type that doesn't exist. You're looking for If it helps, here's a small example of a table that gets updated every so often with a random value: from random import randint, random
from textual.app import App, ComposeResult
from textual.widgets import DataTable
class UpdatingTableExampleApp(App[None]):
def compose(self) -> ComposeResult:
yield DataTable()
def on_mount(self) -> None:
table = self.query_one(DataTable)
table.add_column("Parameter", key="param")
table.add_column("Value", key="value")
for n in range(50):
table.add_row(f"Paramater {n}", 0, key=f"param{n}")
self.set_interval(0.1, self.update_table)
def update_table(self) -> None:
table = self.query_one(DataTable)
row = randint(0, 49)
table.update_cell(f"param{row}", "value", random())
if __name__ == "__main__":
UpdatingTableExampleApp().run() |
Beta Was this translation helpful? Give feedback.
-
sorry about that, I have opened a new discussion - discussions/3379 |
Beta Was this translation helpful? Give feedback.
There's a couple of things that are an issue in the code you post above. First off, you wouldn't use
render
to update a widget like that; therender
method is generally used to provide the renderable value for widget that doesn'tcompose
other widgets.Second: you're trying to perform a CSS type query on a widget type that doesn't exist. You're looking for
ParamView
on itself, but a query looks at all of the descendants of a widget. On top of that,ParamView
in your code is aVertical
, it isn't aDataTable
, so the call toupdate_cell
wouldn't work anyway.If it helps, here's a small example of a table that gets updated every so often with a random value: