简体   繁体   English

Streamlit 动态文本基于 slider 下面

[英]Streamlit dynamic text based on slider below

Streamlit makes dynamic text, based on a slider value, super easy: Streamlit 使基于 slider 值的动态文本变得超级简单:

value = st.slider('Slide me', 0, 100, 50)
if value > 80:
    st.warning('Value is too big!')

How do I issue this warning above the slider?如何在 slider上方发出此警告? This doesn't work:这不起作用:

if value > 80:
    st.warning('Value is too big!')
value = st.slider('Slide me', 0, 100, 50)

The warning will never get displayed when sliding over 80 (actually I'd get an error that value is undefined so I have to set value = 0 at the top).滑动超过 80 时永远不会显示警告(实际上我会收到一个错误,指出value未定义,因此我必须在顶部设置value = 0 )。

You can declare a container (or usingst.empty ) above the slider and then fill it in the conditional that runs after the slider:您可以在 slider 之上声明一个容器(或使用st.empty ),然后在 slider 之后运行的条件中填充它:

container = st.container()
value = st.slider('Slide me', 0, 100, 50)
if value > 80:
    container.warning('Value is too big!')

It could be possible that st.warning does not go "into" the container, then you'd have to define your own warning banner to put in there. st.warning 可能没有 go “进入”容器,那么您必须定义自己的警告横幅以放入其中。 Sorry, cannot test it currently.抱歉,目前无法测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM