#17175·streamlit

selectbox clears on rerun if format_func returns new value, even with the same options.

Author: hashirimCreated Sep 29, 2026Updated Sep 29, 2026
Labelstype:bugarea:widgetsstatus:needs-triagefeature:st.selectboxfeature:st.multiselect

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

Streamlit selectbox gets re-created when formatted labels change, discarding user output.

Reproducible Code Example

python
import streamlit as st
import time

if "start_time" not in st.session_state:
  st.session_state["start_time"] = time.time()

start_time = st.session_state["start_time"]

option = st.selectbox(
  label="Single-select Option",
  options=["A", "B", "C"],
  format_func=lambda option: f"{option}: {int(time.time()-start_time)} seconds ago",
  key="option",
  index=None
)

st.write("Single-select Option:", option)

option2 = st.multiselect(
  label="Multi-select Options",
  options=["D", "E", "F"],
  format_func=lambda option: f"{option}: {int(time.time()-start_time)} seconds ago",
  key="option2",
)

st.write("Multi-select Options:", option2)

Steps To Reproduce

  1. In Single-select Option, Select "A"
  2. In Multi-select Options, Select "D"
  3. In Multi-select Options, Select "E"
  4. In Multi-select Options, Select "F"
  5. Wait 1 second
  6. Click out of the multi select option dropdown

Expected Behavior

It should have option A selected for 'Single-select Option', and options D, E and F selected for 'Multi-select Options'

Current Behavior

Single-select option and multi-select options have nothing selected.

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.63
  • Python version: Python 3.14.7
  • Operating System: Ubuntu 26.4
  • Browser: Firefox 156.0.1

Additional Information

Proposed solution 1: Do not clear the selectbox if the selected options still exist.

Proposed solution 2: Update the selectbox and multiselect documentation with a warning about this. Currently the documentation for format_func says: "This has no impact on the return value of the command." which I would say is incorrect in this case.

This issue seems closely related to issues #11277 and #11268. They seemed to be closed for being fixed in 1.54.1.dev20260204, though I am still seeing this unexpected behavior in 1.63.

Thank you so much for your work on streamlit. It is very amazing!