【发布时间】:2021-02-27 17:40:59
【问题描述】:
我目前正在尝试使用选择框来允许用户选择列的名称来运行模型。当我在侧边栏中放置一个选择框时,我没有遇到问题,但是当我将选择框放在主页上时,只要用户选择一个选项,网页就会重置。代码如下。我还是流光新手,所以我不确定我是否正确使用它。感谢您的帮助!
#add a blank space in the columnName section
columnNames = [" "]
#grab the column names of the dataframe
for column in df.columns:
columnNames.append(column)
#place the selectboxe in the col1 slot
with col1:
#display the column names to the user
#So that they can select the columns they want to use
columnValue = st.multiselect("Select the column:", columnNames)
#place a button in col2 slot
with col2:
#a button to add the selected column to a list of want to use columns
addButtonList = st.button("Add to select list: ")
#when 'addButtonList' is selected take the value from
#'columnValue' and place it on the screen.
if(addButtonList):
st.write(columnValue)
【问题讨论】:
标签: python drop-down-menu streamlit