Is there a way to force LiveBook to reload a cell when an external file has been updated that needs to be read in, and render later impacted cells as stale?
weights_file = "weights.csv"
weights_df = Excel.excel_to_df!(weights_file)
I’ve tried the following suggestion from Claude AI, but that doesn’t work:
# Add this to force reload when files change
_ = File.stat!(weights_file)
Maybe the @external_resource
module attribute can help?
There is no way to automatically reevaluate the cell when that happens. You would need to use a library for watching for the file changes, but then the handling would be asynchronous, not part of the sequential notebook flow.
1 Like
You should be able to use a file watcher and setup a Kino.Proxy to execute the refresh following this example: Kino.Proxy — Kino v0.14.2. I believe the proxy needs an application so you lose interactivity but applications execute top down and stay active. First run could load your initial dataset into weights.csv
and use Kino.start_child to start a file watcher process. You may also be able to just execute it inline but I suspect the supervisor gives you better control. The watcher would listen for changes and make a Req call to your proxy endpoint that refreshes the dataset again.
I’ve yet to validate if this works as I expect it but all of the pieces are there.
1 Like