#17195·streamlit

Programmatically set selections fail for empty selection

Author: sqrx-mcklCreated Sep 29, 2026Updated Sep 29, 2026
Labelstype:bugstatus:needs-triageai-final-review

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

The example in https://docs.streamlit.io/develop/api-reference/data/st.dataframe titled: "Example 2: Programmatically set selections" does not work if we try with empty selections.

Reproducible Code Example

python
import pandas as pd
import streamlit as st
from numpy.random import default_rng as rng

df = pd.DataFrame(rng(0).standard_normal((12, 5)), columns=["a", "b", "c", "d", "e"])

if st.button("Select the first row"):
    st.session_state["data"] = {"selection": {"rows": [0], "columns": [], "cells": []}}
if st.button("Select no row"):
    st.session_state["data"] = {"selection": {"rows": [], "columns": [], "cells": []}}

event = st.dataframe(
    df,
    key="data",
    on_select="rerun",
    selection_mode=["single-row"],
)

st.code(event.selection)

Steps To Reproduce

  1. Run the code
  2. Select a row
  3. Click on the button "Select the first row", it works as expected
  4. Select a row again
  5. Click on the button "Select no row", the dataframe selection state is empty but the table keeps the previous selection.

Expected Behavior

The row selection should match the dataframe selection state and be empty.

Current Behavior

The dataframe selection state is empty but the table keeps the previous selection and is not empty.

Is this a regression?

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

Debug info

  • Streamlit version: 1.63.0
  • Python version: 3.12
  • Operating System: WSL Docker
  • Browser: Edge

Additional Information

I remember it worked in Streamlit version 1.57.0 but I am not sure, I may be mistaken.