Hello Everyone.
I am very new to Streamlit and while building a small webpage i need a bit of help.
import matplotlib.pyplot as plt
import streamlit as st
import random
import time
import multiprocessing
x = []
y = []
x2 = []
y2 = []
i = 0
x_max = 0
y_max = 0
def function1(x_max,y_max,i):
with st.empty():
while True:
with open('data.txt','a') as f:
f.write(str(random.randint(1+i,10+i)) + ',' + str(random.randint(1+i,10+i)) + '\n')
with open("data.txt") as f:
data = f.readlines()[-1]
print(data)
a,b = data.split(',')
a = int(a)
b = int(b)
x.append(a)
y.append(b)
x2.append(a + 2)
y2.append(b + 2)
if x_max<a:
x_max = a
if y_max<b:
y_max = b
fig, ax = plt.subplots()
ax.plot(x,y)
ax.plot(x2,y2)
st.pyplot(fig)
i += 1
time.sleep(0.1)
def function2():
with st.empty():
st.write("Max x:",x_max)
st.write("Max y:",y_max)
time.sleep(0.1)
if __name__ == "__main__":
p1 = multiprocessing.Process(target=function1,args=(x_max,y_max,i))
p2 = multiprocessing.Process(target=function2)
p1.start()
p2.start()
p1.join()
p2.join()
print("Done")
I am trying to read from a file and plotting the data read form the file in a graph.
Although i wanted to draw 2 graphs but i not able to find a way to do so, so i embedded 2 line graphs in one graph.
function 1 will update the graph on regular interval.
while the function 2 should print the maximum value of x and y and update them accordingly.
and over it i am using multiprocessing module to run both this function at the same time.
But when i went to see the output on the browser it just keeps on running and nothing shows up.
Please help.
Thank you…