-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Use key as main identity for st.camera_input widget
#12781
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
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the st.camera_input widget to use the key parameter as the main identity when provided, allowing for dynamic parameter changes without recreating the widget in the frontend.
- Changed
key_as_main_identityfromFalsetoTruein the camera input implementation - Added comprehensive unit tests to verify stable widget ID behavior when using keys
- Added end-to-end tests to validate dynamic property updates while maintaining widget state
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/streamlit/elements/widgets/camera_input.py | Updated key_as_main_identity parameter to True for stable widget identity |
| lib/tests/streamlit/elements/camera_input_test.py | Added unit test to verify widget ID stability with custom keys |
| e2e_playwright/st_camera_input_test.py | Added e2e test for dynamic property updates and updated widget count constants |
| e2e_playwright/st_camera_input.py | Added test case with dynamic camera input properties controlled by toggle |
✅ PR preview is ready!
|
key as main identity for st.camera_input widgetkey as main identity for st.camera_input widget
…ity-for-camera-input
key as main identity for st.camera_input widgetkey as main identity for st.camera_input widget
Describe your changes
If a custom
keyis passed to ast.camera_inputwidget it will be used as the main identity. This allows for dynamically changing other parameters in between reruns without causing the widgets to be recreated in the frontend.GitHub Issue Link (if applicable)
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
Note
Use the widget
keyas the main identity forst.camera_input, and add unit/E2E tests (including a dynamic props scenario) to verify stable IDs and behavior.keyas main identity by settingkey_as_main_identity=Trueinlib/streamlit/elements/widgets/camera_input.py.test_stable_id_with_keyensuring the widget ID remains stable across rerenders with the samekey.st.camera_inputcontrolled by a toggle to changelabel,help, andwidthwhile preserving state (e2e_playwright/st_camera_input.py).NUM_CAMERA_INPUT_WIDGETS=5and update counts; addtest_dynamic_camera_input_propsvalidating label/help updates, width, and preserved value; import/utilize helpersclick_toggle,expect_help_tooltip,expect_prefixed_markdown.Written by Cursor Bugbot for commit df67f0d. This will update automatically on new commits. Configure here.