Created
September 17, 2022 05:47
-
-
Save Merwanski/13369eba0936dae785683615037afe30 to your computer and use it in GitHub Desktop.
streamlit ros python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from streamlit.web import cli as stcli | |
import streamlit as st | |
import rospy | |
from std_msgs.msg import String, Int32 | |
import sys | |
import time | |
mynum=0 | |
mydelta=0 | |
def callback(data): | |
global mydelta, mynum | |
mydelta=mynum-data.data | |
mynum=data.data | |
#rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data) | |
def getData(): | |
return mynum, mydelta | |
rospy.init_node('my_streamlit_ros_node') | |
pub = rospy.Publisher('/mystring', String, queue_size=10) | |
rospy.Subscriber("mynumber", Int32 , callback) | |
def main(): | |
st.title('Streamlit APP:') | |
st.subheader('Commuicating with ROS') | |
mytext = st.text_input('Send String to ROS', 'Life of Brian') | |
pub.publish(mytext) | |
metrics = st.empty() | |
while True: | |
mynum, mydelta=getData() | |
with metrics: | |
st.metric(label="Get Int32 Number from ROS", value=mynum, delta=mydelta, delta_color="inverse") | |
time.sleep(1) | |
if __name__ == '__main__': | |
if st._is_running_with_streamlit: | |
main() | |
else: | |
sys.argv = ["streamlit", "run", sys.argv[0]] | |
sys.exit(stcli.main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment