[英]on_click function assigned to Streamlit button runs before the click event in browser
我正在尝试使用onclick=""
参数在 streamlit 按钮中运行脚本。 问题是,脚本甚至在按钮出现在浏览器上之前就开始运行。 知道这里可能是什么错误吗?
import streamlit as st
from level_packs import create_packs
st.set_page_config(page_title="Main work", page_icon="💻")
st.markdown("# Main work")
st.button('Run script', on_click=create_packs())
我尝试使用以下代码及其工作:)
import streamlit as st
from level_packs import create_packs as f
st.set_page_config(page_title="Main work", page_icon="💻")
st.markdown("# Main work")
def run_button():
st.button('Run script', on_click=f)
run_button()
您可以为按钮初始化 session state 并将 function 传递给if
语句。
就像是:
runbtn = st.button('Run script')
if "runbtn_state" not in st.session_state:
st.session_state.runbtn_state = False
if runbtn or st.session_state.runbtn_state:
st.session_state.runbtn_state = True
create_packs() # Your function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.