File size: 953 Bytes
0e17fbc
1dcdbce
 
 
 
 
9d5aefe
1dcdbce
0e17fbc
1dcdbce
9d5aefe
1dcdbce
 
ba3f31c
1dcdbce
 
 
 
 
 
ba3f31c
1dcdbce
 
 
ba3f31c
1dcdbce
 
ba3f31c
1dcdbce
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import streamlit as st
import pandas as pd
import plotly.express as px
from itertools import count
import random
import time

# Initialize count for x-axis and empty DataFrame for storing data
index = count()
data = pd.DataFrame(columns=['x', 'y'])

# Placeholder for the Plotly chart
chart_placeholder = st.empty()

while True:  # This loop will simulate real-time data updates
    # Append new data point
    new_x = next(index)
    new_y = random.randint(0, 5)
    new_data = pd.DataFrame({'x': [new_x], 'y': [new_y]})
    data = pd.concat([data, new_data], ignore_index=True)

    # Create a new Plotly figure
    fig = px.line(data, x='x', y='y', title="Real-time Data Plot")
    fig.update_layout(xaxis_title='X Axis', yaxis_title='Y Axis', autosize=True)

    # Display the figure using Streamlit
    chart_placeholder.plotly_chart(fig, use_container_width=True)

    # Pause for a moment before updating the chart with new data
    time.sleep(1)