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.
De-experimentalize st.fragment (streamlit#9019)
We've had a few bugs filed and additional features requested for `@st.experimental_fragment`, but for the most part, the feature seems to work quite well / we haven't seen much evidence that any drastic changes to the API are required. While we may still make some tweaks to the feature going forward, it does seem ok at this point to drop the `experimental_` prefix for the decorator to make it an officially supported part of the Streamlit API! This PR de-experimentalizes the `@st.fragment` decorator, and in the process it makes the following changes to the feature. * `st.rerun(scope="fragment")` can now be called from within a fragment to rerun only that fragment. We also added `st.rerun(scope="app")`, which functions the same way as calling `st.rerun()` without an argument does today. * fragments can now be nested, which includes allowing developers to call fragments from within a dialog. Note: it is still prohibited to create a dialog from within a dialog. * it is now explicitly prohibited for a fragment to write a widget outside of the fragment. * various bugfixes, including: * Exceptions raised from within a fragment can no longer interrupt other "simultaneously" running fragments. * Exceptions raised from within a fragment now print their error messages inside of the fragment's container rather than "globally" in the app. * We no longer incorrectly reraise `RuntimeError`s when a `KeyError` is raised within a fragment. * This may not completely get rid of instances where we're seeing users run into `RuntimeError`s with the message `"Could not find fragment with id <fragment_id>"`, but I do expect a substantial number of them to go away. Closes streamlit#8635 Closes streamlit#8494 Closes streamlit#8591 --------- Co-authored-by: Benjamin Räthlein <[email protected]>
- Loading branch information
Showing
58 changed files
with
1,241 additions
and
298 deletions.
There are no files selected for viewing
Binary file modified
BIN
-3.6 KB
(89%)
...ht/__snapshots__/linux/st_dialog_test/st_dialog-with_inline_error[chromium].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
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
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
46 changes: 0 additions & 46 deletions
46
e2e_playwright/st_experimental_fragment_multiple_fragments_test.py
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
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,41 @@ | ||
# 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. | ||
|
||
import time | ||
from uuid import uuid4 | ||
|
||
import streamlit as st | ||
|
||
if "sleep_time" not in st.session_state: | ||
st.session_state["sleep_time"] = 0 | ||
sleep_time = st.session_state["sleep_time"] | ||
|
||
|
||
@st.fragment | ||
def my_fragment(n): | ||
with st.container(border=True): | ||
st.button("rerun this fragment", key=n) | ||
st.write(f"uuid in fragment {n}: {uuid4()}") | ||
# sleep here so that we have time to react to the flow | ||
# and trigger buttons etc. before the fragment is finished | ||
# and the next starts to render | ||
time.sleep(sleep_time) | ||
|
||
|
||
my_fragment(1) | ||
my_fragment(2) | ||
my_fragment(3) | ||
|
||
st.session_state["sleep_time"] = 3 | ||
st.button("Full app rerun") |
Oops, something went wrong.