Hello im trying to plot data in a column layout but i only want to update the bar chart and not to create new instances of the bar charts. but everything i tried from the documentation only results in a plot of new bar charts instead of updating.
what am i doing wrong? can anyone help me?
import streamlit as st
import pandas as pd
import numpy as np
from opcua import Client
import time
import OPC_Nodes as nodes
client = Client("opc.tcp://172.25.73.114:4840")
#*****************************************************************************************************************
def getOpcStates(nodes):
client.connect()
states = {}
for node in nodes:
states[node] = client.get_node(node).get_value()
client.disconnect()
return states
#*****************************************************************************************************************
st.set_page_config(layout="wide")
st.title("OPC Testsignale")
st.divider()
col1, col2 = st.columns(2 ,gap="small")
col1.subheader("Basic 1")
col2.subheader("Basic 2")
# if ('Basic1' not in st.session_state):
# st.session_state['Basic1']=pd.DataFrame([[0,100]]) #empty data frame
# if ('Basic2' not in st.session_state):
# st.session_state['Basic2']=pd.DataFrame([[0,100]]) #empty data frame
# col3.subheader("Regal3")
# col4.subheader("Regal4")
# col5.subheader("Regal5")
# Test = np.random.randn(20,3)
# print(Test)
# chart_data1 = pd.DataFrame([[30,70]])
# st.bar_chart(chart_data1)
# col3.bar_chart([[80,20]], x_label="", y_label="FĂĽllstand %", stack="normalize", color=["#ff0000","#00ff00"])
# col4.bar_chart([[50,50]], x_label="", y_label="FĂĽllstand %", stack="normalize", color=["#ff0000","#00ff00"])
# col5.bar_chart([[60,40]], x_label="", y_label="FĂĽllstand %", stack="normalize", color=["#ff0000","#00ff00"])
try:
while True:
time.sleep(1)
#************************************************************ BasicLine1
states = getOpcStates(nodes.BasicLine1)
sum = 0
for node in states:
print(node, "->", states[node])
if states[node] == True:
sum += 1
pos = 100/len(states) * sum
neg = 100 - pos
with col1.empty():
st.bar_chart([[pos,neg]], x_label="", y_label="FĂĽllstand %", stack="normalize", color=["#00ff00","#ff0000"])
#************************************************************ BasicLine2
states = getOpcStates(nodes.BasicLine2)
sum = 0
for node in states:
print(node, "->", states[node])
if states[node] == True:
sum += 1
pos = 100/len(states) * sum
neg = 100 - pos
with col2.empty():
st.bar_chart([[pos,neg]], x_label="", y_label="FĂĽllstand %", stack="normalize", color=["#00ff00","#ff0000"])
#************************************************************
except KeyboardInterrupt:
client.disconnect()