This shows how to watch a local directory and load files in aDocumentation Index
Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
Use this file to discover all available pages before exploring further.
Table as they are added to the directory.
Atoti is designed to efficiently handle data updates in its tables.
When tables are updated, the new data will automatically be taken into account when querying the session.
Let’s take the example of an application analyzing sales of a company.
Sales data is stored in one CSV file for each day.
Each day, a new CSV containing the sales of the day will be created and we want to load it into the application.
Creating the session
Let’s load the CSV files of thecurrent folder in an Atoti session:
Starting the file watcher
We’ll use the popular watchdog library to watch our directory:Simulating the arrival of a new file
Seeing widgets change in real time
We can redo the same operation with the app opened on one side with a pivot table making a real-time query. The widget will rerender automatically to display the new date too:
Going further
- watchdog supports multiple FileEvents, not just the creation of a file as described here.
- If you need to preprocess the watched files before loading them into the Atoti session, you can do it inside the
on_created()method of the event handler by first reading the file withpandas.read_csv(), editing the resulting dataframe, and then passing it toatoti.Table.load(). - If you want to do multiple actions (e.g. dropping rows before loading new ones) when a file is updated, you can use
data_transaction().