Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,30 @@
|
|
| 1 |
-
import time
|
| 2 |
-
import requests
|
| 3 |
-
|
| 4 |
import streamlit as st
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
return None
|
| 13 |
-
return r.json()
|
| 14 |
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
time.sleep(5)
|
| 27 |
-
st.balloons()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import plotly.express as px
|
| 4 |
+
from itertools import count
|
| 5 |
+
import random
|
| 6 |
+
import time
|
| 7 |
|
| 8 |
+
# Initialize count for x-axis and empty DataFrame for storing data
|
| 9 |
+
index = count()
|
| 10 |
+
data = pd.DataFrame(columns=['x', 'y'])
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# Placeholder for the Plotly chart
|
| 13 |
+
chart_placeholder = st.empty()
|
| 14 |
|
| 15 |
+
while True: # This loop will simulate real-time data updates
|
| 16 |
+
# Append new data point
|
| 17 |
+
new_x = next(index)
|
| 18 |
+
new_y = random.randint(0, 5)
|
| 19 |
+
new_data = pd.DataFrame({'x': [new_x], 'y': [new_y]})
|
| 20 |
+
data = pd.concat([data, new_data], ignore_index=True)
|
| 21 |
|
| 22 |
+
# Create a new Plotly figure
|
| 23 |
+
fig = px.line(data, x='x', y='y', title="Real-time Data Plot")
|
| 24 |
+
fig.update_layout(xaxis_title='X Axis', yaxis_title='Y Axis', autosize=True)
|
| 25 |
|
| 26 |
+
# Display the figure using Streamlit
|
| 27 |
+
chart_placeholder.plotly_chart(fig, use_container_width=True)
|
| 28 |
|
| 29 |
+
# Pause for a moment before updating the chart with new data
|
| 30 |
+
time.sleep(1)
|
|
|
|
|
|