Benjamin-Philip

Benjamin-Philip

I’ve got a GenServer with some tabular data that updates frequently. I would like to be able to render this live data. Presently, the way to go seems to create a smart cell for this, and write some custom JS to render my table. However, Kino.DataTable fits all my needs, and I just need a way of updating it. So, I would like to do this without replicating what’s already there in Kino.DataTable.

How do I render live data with a Kino.DataTable?

First 7 of 7 Posts Switch mode

jonatanklosko

jonatanklosko

Creator of Livebook

You can use Kino.Frame and render new Kino.DataTable into the frame as needed.

Benjamin-Philip

Benjamin-Philip OP

@jonatanklosko, I had tried this out earlier by modifying the Kino.Frame docs for a DataTable like this:

frame = Kino.Frame.new() |> Kino.render()

for i <- 1..100 do
  table = Kino.DataTable.new([%{no: i}])

  Kino.Frame.render(frame, table)
  Process.sleep(50)
end

This didn’t render, and I thought that Kino.Frame was not the way to go. However, when I saw your reply, I increased the sleep time to 100 miliseconds and I got a very jittery rendering. Things stabilized once I increased the sleep time to a second. I guess what was happening was that the DataTable took more that 50ms to render, so re-rendering it at that speed led to nothing being rendered at all (except at the last re-render).

Perhaps a note in the Kino.Frame docs regarding this would be a good idea?

Even re-rendering every second is slightly jittery because the entire DataTable has to be re-rendered. The render cell momentarily disappears while the DataTable is rendering. I am guessing this is because we are also re-rendering the Table interface, reloading the associated js and css etc. One way to optimize this is to reload only the data, and not the table viewer itself. After that, I could apply diffs instead. This is out of Kino.DataTable’s scope, so writing my own JS doesn’t seem to much to ask.

jonatanklosko

jonatanklosko

Creator of Livebook

Oh, I assumed you don’t need to re-render so often. The slow re-render is less about Kino.Frame and more about Kino.DataTable, which is rendered inside an iframe (as are all Kino.JS), so it does need to load and run the JS again. If you want the table to quickly react to updates, then it should be a single Kino.JS.Live reacting to events.

We have a lower-level abstraction called Kino.Table, where you have more control over how you query the data, and you can enable a “Refetch” button to re-run the query. However, that’s still not reactive.

The current design of Kino.DataTable is very much static. To make it reactive we could add Kino.Table.update, which would invoke a new callback @callback update(update_arg) to update the state and then re-fetch and broadcast the current page. And then we could add Kino.DataTable.update(tabular) and implement the callback, which would be similar to the current Kino.Table.new and @callback init(init_arg).

cc @josevalim

Benjamin-Philip

Benjamin-Philip OP

That’s what I thought.

That sounds great. Like you and I said, this is out of DataTable’s scope, but Elixir being a language that puts a lot of emphasis on being able to handle live data, I think a way to deal with live updates would be appreciated.

Maybe if Table.update works out, we could add a Table.listen.

josevalim

josevalim

Creator of Elixir

Yes, allowing the data table to be updated would be great.

jonatanklosko

jonatanklosko

Creator of Livebook

Like you and I said, this is out of DataTable ’s scope

To be clear, I meant that it’s static now, but we could support the update : )

Yes, allowing the data table to be updated would be great.

I opened an issue, so that we don’t forget.

Benjamin-Philip

Benjamin-Philip OP

That’s fine too! I didn’t notice your last sentence in that quote.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

We're in Beta

About us Mission Statement