Updating clients when Data Tables data changes

Hello,

I’m building a simple In/Out Staff board that would let our department keep track of who’s on-site on what days (to help comply with our organization’s COVID19 safety requirements). No user management, just a single page that uses a bunch of checkboxes next to each employee’s name to denote the day of the week. I’m using a data table and simple data bindings.

My question is, what’s the simplest way to update all the clients (anyone who has their web browser already open to the page) if a change to the data table occurs (such as one employee updating what days they’ll be in or out). Do I need to write JS code that polls the server? Or is there an existing Anvil mechanism like a persistent websocket back-channel from the client and server-side on-change type event I can use?

Any suggestions appreciated.

Thanks!
Ken

Welcome to the Forum!

Polling the Server does not require any JavaScript. Whatever Python code you use to update the web page, you can use a Timer component to run it again, periodically.

If you want all the check-boxes to operate independently, then you will likely need each one to have its own database record. Otherwise, conflicts can occur when two different users (unknowingly) try to write to the same record. (Example: a record with two check-boxes, A and B, initially unchecked. User 1 checks box A, and leaves B unchecked. User 2 does the reverse. Which version of the record should survive: the one with only A checked, or only B? If A and B are in different records, though, then no such conflict can occur.)

At the moment, I’m not aware of any mechanism that would push data from the Server to the Browser. All Browser-side activity is driven by code executing in the Browser.

Thanks for the reply. I’m not using any Python code at the moment, just the data bindings via the UI builder tool. What method would I call using a Timer to get the page to update in this case?

I’m not too concerned about concurrency here, as each user record has all of it’s own boolean fields for each day, and unless it’s an accident, users would only be changing their own checkboxes on the page. And it’s not disastrous if the type of conflict you describe occurs.

Loving how quickly I can prototype a solution with Anvil!

MULTIPLE EDITS: Finally figured it out. Not the most elegant way, but good enough…

 def timer_1_tick(self, **event_args):
    self.refresh_data_bindings()
    self.repeating_panel_1.items = app_tables.table_0.search()
  pass

Cheers,
Ken

1 Like