eaglelandsonce's picture
Update app.py
1dcdbce verified
raw
history blame contribute delete
953 Bytes
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)