forked from streamlit/streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dataframe maximum update depth error (streamlit#9490)
## Describe your changes Fixes an issue with the dataframe component that causes random crashes:  The crash can happen on low-resolution monitors if dataframes are rendered with `use_container_width=True` are used in some of our containers (popover, tabs, sidebar, columns). It appears that our width calculation in the Block component causes this. If the width can't be determined yet by the resize observer, it can be -1 for some time. This seems to be a trigger for the maximum update depth. Unfortunately, I don't have a validated explanation of why it actually leads to the error :( ## GitHub Issue Link (if applicable) - Closes streamlit#7949 ## Testing Plan - Add e2e test to discover similar breakage. --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
- Loading branch information
1 parent
5622102
commit 7f43ef6
Showing
5 changed files
with
164 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""This test checks that the dataframe component renders without crashing | ||
when used in different containers. | ||
This mainly addresses this issue: https://github.com/streamlit/streamlit/issues/7949 | ||
""" | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
import streamlit as st | ||
|
||
np.random.seed(0) | ||
df = pd.DataFrame(np.random.randn(20, 5), columns=["a", "b", "c", "d", "e"]) | ||
|
||
use_container_width = st.toggle("use_container_width", True) | ||
|
||
with st.popover("popover"): | ||
st.dataframe(df, use_container_width=use_container_width) | ||
|
||
with st.sidebar: | ||
st.dataframe(df, use_container_width=use_container_width) | ||
|
||
tab1, tab2 = st.tabs(["Tab 1", "Tab 2"]) | ||
|
||
col1, col2, col3 = tab1.columns([1, 2, 3]) | ||
col1.dataframe(df, use_container_width=use_container_width, height=100) | ||
col2.dataframe(df, use_container_width=use_container_width, height=100) | ||
col3.dataframe(df, use_container_width=use_container_width, height=100) | ||
|
||
tab1.dataframe(df, use_container_width=use_container_width, height=100) | ||
tab2.dataframe(df, use_container_width=use_container_width, height=100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
from playwright.sync_api import Page, expect | ||
|
||
from e2e_playwright.conftest import wait_for_app_loaded | ||
from e2e_playwright.shared.app_utils import click_toggle | ||
|
||
|
||
def test_dataframe_renders_without_crashing(app: Page): | ||
"""Test that st.dataframe renders without crashing.""" | ||
|
||
# Reload the page a couple of times to make sure that the dataframe | ||
# crash doesn't appear. | ||
# This test is safeguarding against potential regressions that | ||
# cause crashes as report in: https://github.com/streamlit/streamlit/issues/7949 | ||
# But these crashes are usually more random, thats why we run | ||
# it for a couple of page reloads. | ||
# Also, even if there are crashes, its not gurunteed that they will | ||
# happen in our CI environment. | ||
for _ in range(5): | ||
dataframe_elements = app.get_by_test_id("stDataFrame") | ||
expect(dataframe_elements).to_have_count(7) | ||
expect(app.get_by_test_id("stAlertContainer")).not_to_be_attached() | ||
|
||
# Set use_container_width to False: | ||
click_toggle(app, "use_container_width") | ||
dataframe_elements = app.get_by_test_id("stDataFrame") | ||
expect(dataframe_elements).to_have_count(7) | ||
expect(app.get_by_test_id("stAlertContainer")).not_to_be_attached() | ||
|
||
# Reload the page: | ||
app.reload() | ||
wait_for_app_loaded(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters