This project provides a simple yet powerful web-based application for visualizing real-time streaming numerical data. It leverages Flask as a backend server to watch a local log file for changes and Flask-SocketIO for WebSocket communication to push new data to the frontend. The client-side, built with HTML, JavaScript, and Plotly.js, displays the data as an interactive scatter plot, offering zoom, pan, and reset functionalities.
This system is ideal for monitoring sensor readings, log file metrics, or any application where continuous, live data visualization is beneficial.
- Real-time Data Streaming: Utilizes WebSockets (via Flask-SocketIO) for efficient, low-latency data transfer from server to client.
- File Monitoring: The Flask backend uses
watchdog
to detect changes in a specified log file, simulating a live data source. - Interactive Plotting: Plotly.js on the frontend provides a dynamic scatter plot with built-in:
- Zoom (mouse wheel, drag-box)
- Pan (drag)
- Reset view
- Hover tooltips for data points.
- Cross-platform Compatibility: Designed to run on various operating systems where Python and modern web browsers are supported.
- Clear Data Format: Explicit handling of numerical data points for sequential plotting.
Follow these steps to get the project up and running on your local machine.
- Python 3.x (recommended 3.8+)
pip
(Python package installer)
-
Clone the repository:
git clone git@github.com:oysteijo/logplotter.git cd logplotter
-
Create and activate a Python virtual environment (recommended):
python3 -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate
-
Install the required Python packages: Install the packages listed in the
requirements.txt
file in your project's root directory. It should have the following content:Flask Flask-SocketIO watchdog
Then, install them:
pip install -r requirements.txt
Warning: I tried this on several systems Ubuntu, Arch Linux, RedHat EL, but it seems to me that there are some problems if you install Flask and Flask-SocketIO from system packages (
.rpm
,.deb
, pacman). It is therefore strongly recommended that you use a virtual environment.
-
Prepare your data source: The
app.py
is configured to monitor a file namedtest_data.log
(you can change this filename inapp.py
). You can create this file:touch test_data.log
To simulate live data, you can append numerical values to this file. For example, open it in a text editor and add numbers, or use
echo
:echo "12.34" >> test_data.log echo "15.67" >> test_data.log # ... and so on
Each new line added to
test_data.log
should contain a single numerical value. -
Run the Flask server:
python app.py test_data.log --debug
The server will start, typically on
http://127.0.0.1:5000
. You will see logging messages indicating the server's activity and when data points are sent. -
Open the client in your web browser: Navigate to
http://127.0.0.1:5000
in your preferred web browser. The plot will load. Any data already intest_data.log
will be displayed as "initial data." -
Observe real-time updates: As you append new numerical values to
test_data.log
(e.g., usingecho "20.1" >> test_data.log
), you will see the plot update in real-time in your browser. Use your mouse to zoom, pan, and interact with the Plotly.js chart. Click "Reset View" to revert to the initial zoom level.
The system expects numerical data points for plotting.
initial_data
event: Sends an array of historical numerical values (e.g.,[10.5, 12.3, 11.8, 15.0]
). The client plots these sequentially, using the array index as the X-axis value.new_data
event: Sends a single numerical value (e.g.,20.1
). The client appends this value to the existing data, incrementing the X-axis index.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
This project is licensed under the BSD 3-clause License - see the LICENSE file for details.