【问题标题】:How carry out specific task with multiselect in streamlit?如何在streamlit中使用多选执行特定任务?
【发布时间】:2020-05-27 12:03:56
【问题描述】:

我想根据 STREAMLIT 多选选项(特定任务)执行一项或两项操作,但我看不出我做错了什么。请问有什么办法解决吗?

我的代码:

import streamlit as st

calculation = st.multiselect("Select one or both operations:", ('SUM','DIV'))

if calculation =='SUM':st.write(2+2)

elif calculation =='DIV':st.write(10/2)

【问题讨论】:

    标签: python machine-learning streamlit


    【解决方案1】:

    st.multiselect 返回一个包含所选选项的数组

    import streamlit as st
    
    calculation = st.multiselect("Select one or both operations:", ('SUM','DIV'))
    
    if 'SUM' in calculation:
        st.write(2+2)
    
    if 'DIV' in calculation:
        st.write(10/2)
    
    

    【讨论】:

    • 非常感谢乔纳森 R.!
    猜你喜欢
    • 1970-01-01
    • 2016-02-25
    • 2012-02-21
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    • 2018-05-19
    • 1970-01-01
    相关资源
    最近更新 更多