Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the simply-static domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6121
实时变化的流程图-streamlit系列

实时变化的流程图-streamlit系列

实时变化的流程图

import streamlit as st
import graphviz

if 'num' not in st.session_state:
    st.session_state.num = "1"

def update2():
    st.session_state.num = "2"

def update3():
    st.session_state.num = "3"

st.write(st.session_state.num)
st.button("Perform calculation 2", on_click=update2, key='key_2')
st.button("Perform calculation 3", on_click=update3, key='key_3')

graph= graphviz.Digraph(graph_attr={'rankdir':'LR'})
graph.edge(f'3', '12 ', label='3*4')
graph.edge(f'4', '12 ', label='4*3')
graph.edge('12 ', '12', label='max(0,12)')
graph.edge('12', '60', label='12*5')
graph.edge(st.session_state.num, '60', label='5*12')
graph.edge('60', '1600', label='(100 - 60)**2')

#red arrows

graph.edge('1600', '60', label='2*(100 - 60)=80', color='red')
graph.edge('60', '12', label='5*80=400', color='red',)
graph.edge('60', st.session_state.num, label='12*80=960', color='red')
graph.edge('12', '12 ', label='1*400=400', color='red')
graph.edge('12 ', '3', label='400*4=1600', color='red')
graph.edge('12 ', '4', label='400*3=1200', color='red')

st.graphviz_chart(graph)