Configure a selectbox column in st.dataframe or st.data_editor.
This is the default column type for Pandas categorical values. This command needs to be used in the column_config parameter of st.dataframe or st.data_editor. When used with st.data_editor, editing will be enabled with a selectbox widget.
Function signature[source] | |
---|---|
st.column_config.SelectboxColumn(label=None, *, width=None, help=None, disabled=None, required=None, pinned=None, default=None, options=None) | |
Parameters | |
label (str or None) | The label shown at the top of the column. If this is None (default), the column name is used. |
width ("small", "medium", "large", or None) | The display width of the column. If this is None (default), the column will be sized to fit the cell contents. Otherwise, this can be one of the following:
|
help (str or None) | An optional tooltip that gets displayed when hovering over the column label. If this is None (default), no tooltip is displayed. |
disabled (bool or None) | Whether editing should be disabled for this column. If this is None (default), Streamlit will decide: indices are disabled and data columns are not. If a column has mixed types, it may become uneditable regardless of disabled. |
required (bool or None) | Whether edited cells in the column need to have a value. If this is False (default), the user can submit empty values for this column. If this is True, an edited cell in this column can only be submitted if its value is not None, and a new row will only be submitted after the user fills in this column. |
pinned (bool or None) | Whether the column is pinned. A pinned column will stay visible on the left side no matter where the user scrolls. If this is None (default), Streamlit will decide: index columns are pinned, and data columns are not pinned. |
default (str, int, float, bool, or None) | Specifies the default value in this column when a new row is added by the user. This defaults to None. |
options (Iterable of str or None) | The options that can be selected during editing. If this is None (default), the options will be inferred from the underlying dataframe column if its dtype is "category". For more information, see Pandas docs). |
Examples
import pandas as pd import streamlit as st data_df = pd.DataFrame( { "category": [ "π Data Exploration", "π Data Visualization", "π€ LLM", "π Data Exploration", ], } ) st.data_editor( data_df, column_config={ "category": st.column_config.SelectboxColumn( "App Category", help="The category of the app", width="medium", options=[ "π Data Exploration", "π Data Visualization", "π€ LLM", ], required=True, ) }, hide_index=True, )
Still have questions?
Our forums are full of helpful information and Streamlit experts.