Skip to content

st.altair_chart() "Unrecognized data set" error interrupts chart rendering #11906

@foldager

Description

@foldager

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

When using st.altair_chart() with sidebar widgets, a race condition occurs during app reruns that causes Altair charts to fail with the error Uncaught (in promise) Error: Unrecognized data set: <hash>. The error appears in the browser console, chart rendering is interrupted showing a blank x-axis, and the chart only renders properly when the mouse is moved.

Image

Reproducible Code Example

import streamlit as st
import altair as alt
import pandas as pd
import numpy as np

# Add 10 sidebar widgets, each with 1000 different options.
for i in range(10):
    st.sidebar.selectbox(
        f"Widget {i}",
        [f"Option {j}" for j in range(1000)],
    )

# Generate sample data
n_points = 8000
data = pd.DataFrame({
    'x': np.random.randn(n_points),
    'y': np.random.randn(n_points),
    'category': np.random.choice(['A', 'B', 'C'], n_points),
})

# Line chart
lines = alt.Chart(data).mark_line().encode(
    x=alt.X('x:Q'),
    y=alt.Y('y:Q'),
    color=alt.Color('category:N'),
)

# 10 text overlay labels
labels = alt.Chart(data.head(10)).mark_text().encode(
    x=alt.X('x:Q'),
    y=alt.Y('y:Q'),
    text=alt.Text('category:N'),
)

st.altair_chart(lines + labels, use_container_width=True)

st.button("rerun")

Steps To Reproduce

  1. Run the above code snippet with streamlit run ...
  2. Click the "rerun" button repeatedly
  3. Open browser developer console to see the error
  4. Observe the chart behavior

Expected Behavior

The Altair chart should render correctly on every rerun without errors, displaying the line chart with text labels consistently.

Current Behavior

  • Error in browser console: Uncaught (in promise) Error: Unrecognized data set: 1760930fca8bdd09f674f91f30b801ed (hash varies)
  • Visual symptoms:
    • Chart rendering is interrupted
    • Blank x-axis is displayed
    • Chart only renders properly when the mouse is moved over the chart area (probably firing chart re-render)
  • Reproducibility: The bug is non-deterministic but on my system it can be reproduced reliably with the data set size and number of widgets in the example code

Is this a regression?

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

Debug info

  • Streamlit version: 1.46.1
  • Python version: 3.13.2
  • Altair version: 5.5.0
  • OS version: macOS (Darwin)
  • Browser version: Chrome (error appears in browser console)

Additional Information

Investigation of the Vega-Lite source before and after hitting rerun shows that the hash mentioned in the error corresponds to the outgoing (old) dataset. This indicates a race condition where the "old" plot attempts to render after its dataset has already been removed from the Vega-Lite data registry.

The error can also happen for non-layered charts, but in that case the chart renders as opposed to blanking out.

  • The error hash corresponds to a Vega-Lite dataset identifier
  • The issue appears to be a race condition in the chart update lifecycle
  • The bug is reliably reproducible with larger datasets and multiple sidebar widgets
  • Removing the sidebar widgets reduces the frequency of the problem to the point it can be hard to reproduce

Metadata

Metadata

Assignees

Labels

feature:st.altair_chartRelated to the `st.altair_chart` elementpriority:P2Medium-high priority - fix within one monthstatus:confirmedBug has been confirmed by the Streamlit teamtype:bugSomething isn't working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions