实时变化的流程图-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)

销售查询

from streamlit_option_menu import option_menu
import pandas as pd
import streamlit as st
from st_aggrid import AgGrid
from st_aggrid.grid_options_builder import GridOptionsBuilder
from st_aggrid.shared import ColumnsAutoSizeMode
from st_aggrid import GridOptionsBuilder, AgGrid, GridUpdateMode
import streamlit.components.v1 as components

custom_css = {
    ".ag-row-hover": {"background-color": "#98FB98 !important"},
    ".ag-row-odd": {"background-color": "#FFF8DC"},
    ".ag-row-even": {"background-color": "#D2B48C"},
    ".ag-root-wrapper": {"border": "3px solid #98FB98"},
    ".ag-header": {"background-color": "#2c2d30"},
    ".ag-status-bar": {"background-color": "#232323"},
    ".ag-right-cols-container": {"background-color": "#98FB98"},
    ".ag-side-buttons": {"background-color": "#2c2d30"},
    ".ag-paging-panel": {"background-color": "#98FB98"},
    ".ag-root": {"background-color": "#98FB98"},
    ".ag-cell-focus .ag-cell-value": {"background-color": "#4895ef !important"},
    ".ag-root": {"background-color": "#98FB98"},
    ".ag-cell-focus .ag-cell-value": {"background-color": "#4895ef !important"},
    ".ag-row-selected": {"color": "#4895ef !important"},
    ".ag-theme-streamlit": {'transform': "scale(0.8)", "transform-origin": '0 0'}
}

components.iframe("https://www.mixdiy.com/",650,800)


df = pd.read_excel(r"C:\Users\1\Downloads\ab.xls")

#gb = GridOptionsBuilder.from_dataframe(df, min_column_width=100)
#AgGrid(df, gridOptions=gb.build(), fit_columns_on_grid_load=True)

other_options = {'suppressColumnVirtualisation': True}
gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_pagination(paginationAutoPageSize=True)
gb.configure_grid_options(**other_options)
gridOptions = gb.build()
AgGrid(df,gridOptions,columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,custom_css=custom_css)
hide_streamlit_style = """
                        <style>
                        #MainMenu {visibility: hidden;}
                        footer {visibility: hidden;}
                        </style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)

密码保护:exc

此内容受密码保护。如需查阅,请在下列字段中输入您的密码。

适用于windows的ubuntu子系统出现WSL2:Temporary Failure in Name Resolution解决方法

WSL2: Temporary Failure in Name Resolution

In WSL2, run:

登录后复制 
# remove existing resolv.conf symlink that is pointing to a wrong nameserver
sudo rm /etc/resolv.conf
# create a new resolv.conf with a correct nameserver
sudo bash -c 'echo "nameserver 1.1.1.1" > /etc/resolv.conf'
# stop wsl from regenerating resolv.conf symlink
sudo bash -c 'printf "[network]\ngenerateResolvConf = false" > /etc/wsl.conf'
# make current resolv.conf immutable so that wsl does not delete it
sudo chattr +i /etc/resolv.conf



In powershell, run

wsl --shutdown
wsl
出现问题No module named pip的解决
sudo apt update
sudo apt upgrade -y
sudo apt install --fix-missing python3-pip

streamlit运行参数

streamlit run app.py --server.port 80

以上以80端口运行

import numpy as np
import pandas as pd
import streamlit as st
x = st.slider("选择一个数字", 0, 100)
st.write(x, "的平方是", x * x)

chart_data = pd.DataFrame(
    np.random.randn(20, 3),
    columns = ['a', 'b', 'c'])

st.area_chart(chart_data)

hide_streamlit_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)

以上代码隐藏了streamlit的logo

实现一键开关机的树莓派伴侣配置程序

这是树莓派官方操作系统Raspberry Pi OS (64-bit)的配置程序

请下载对应自己操作系统的压缩文件,这里以64位树莓派官方操作系统为例

下载文件后解压

unzip pimateone64.zip

解压后在解压文件所在目录以su用户运行

sudo ./pimateone64

配置程序执行完毕后系统会自动重启,等待树莓派启动后即可使用mateone按钮实现树莓派的正常开关机。

注意:树莓派关机需要一定时间,关机过程中不要按下mateone的按键(按下了也不起作用😊)

附:查看自己的系统类型

getconf LONG_BIT

返回64,即为64位系统,对应本文的例子。返回32,即为32位系统,需下载pimateone32

c程序