Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error message to show dataframes and charts (when used as widgets) can't be assigned values through Session State #8715

Closed
3 of 4 tasks
sfc-gh-dmatthews opened this issue May 19, 2024 · 1 comment · Fixed by #8720
Labels
area:widgets feature:st.session_state status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working

Comments

@sfc-gh-dmatthews
Copy link
Contributor

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

For the current streamlit-nightly and soon-to-be 1.35.0, we've introduced turning dataframes and some charts into widgets. Their values cannot be assigned through Session State.

Reproducible Code Example

import streamlit as st
import plotly.express as px

df = px.data.iris() # iris is a pandas DataFrame
fig = px.scatter(df, x="sepal_width", y="sepal_length")

st.session_state.x = {}
x = st.plotly_chart(fig, use_container_width=True, key="x", on_select="rerun")

Steps To Reproduce

Run the code and observe the (expected) error:

SESSION_STATE_WRITES_NOT_ALLOWED_ERROR_TEXT = """
Values for st.button, st.download_button, st.file_uploader, st.data_editor,
st.chat_input, and st.form cannot be set using st.session_state.
"""

Expected Behavior

The error message should include the newly introduced read-only widgets: st.dataframe, st.vega_lite_chart, st.altair_chart, and st.plotly_chart.

Current Behavior

Error displayed from here:

SESSION_STATE_WRITES_NOT_ALLOWED_ERROR_TEXT = """
Values for st.button, st.download_button, st.file_uploader, st.data_editor,
st.chat_input, and st.form cannot be set using st.session_state.
"""

Is this a regression?

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

Debug info

  • Streamlit version:
  • Python version:
  • Operating System:
  • Browser:

Additional Information

No response

@sfc-gh-dmatthews sfc-gh-dmatthews added type:bug Something isn't working status:needs-triage Has not been triaged by the Streamlit team labels May 19, 2024
Copy link

If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.

Your feedback helps us prioritize which bugs to investigate and address first.

Visits

@LukasMasuch LukasMasuch added area:widgets status:confirmed Bug has been confirmed by the Streamlit team feature:st.session_state and removed status:needs-triage Has not been triaged by the Streamlit team labels May 20, 2024
LukasMasuch added a commit that referenced this issue May 24, 2024
## Describe your changes

The error message used when writing session state for certain widgets
that disallow does not include the new selection cases. This PR makes
the exception message a bit more generic so that it is easier to
maintain in a world where a lot of elements can become widgets. The
widget command is included in the stack trace anyway:

<img width="725" alt="image"
src="https://github.com/streamlit/streamlit/assets/2852129/c871ff7a-e6d1-4d99-b2c9-167994dea24b">

This also follows the same style as the other exception we throw in the
same context.

## GitHub Issue Link (if applicable)

- Closes #8715

## Testing Plan

- Updated tests, not new logic was added.

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:widgets feature:st.session_state status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants