eaglelandsonce commited on
Commit
1dcdbce
·
verified ·
1 Parent(s): 05f49c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -24
app.py CHANGED
@@ -1,32 +1,30 @@
1
- import random
2
- from itertools import count
3
- import plotly.express as px
4
- import pandas as pd
5
- import matplotlib.pyplot as plt
6
- from matplotlib.animation import FuncAnimation
7
  import streamlit as st
 
 
 
 
 
8
 
9
- plt.style.use('fivethirtyeight')
10
-
11
- x_vals = []
12
- y_vals = []
13
  index = count()
 
14
 
15
- def animate(i):
16
- x_vals.append(next(index))
17
- y_vals.append(random.randint(0, 5))
18
- plt.cla() # Clear the current axes.
19
- plt.plot(x_vals, y_vals)
20
-
21
- # fig, ax = plt.subplots() # Create a figure and an axes to plot.
22
- # ani = FuncAnimation(fig, animate, interval=1000)
23
-
24
- ani = FuncAnimation(plt.gcf(), animate, interval=1000)
25
-
26
 
27
- # st.pyplot(fig) # Use this line if integrating with Streamlit
 
 
 
 
 
28
 
29
- plt.tight_layout()
 
 
30
 
 
 
31
 
32
- st.write(plt.show())
 
 
 
 
 
 
 
 
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)