Skip to content

Conversation

@mikeprosserni
Copy link
Collaborator

@mikeprosserni mikeprosserni commented Jun 30, 2025

What does this Pull Request accomplish?

This PR upgrades how inputs work for streamlit pages.

  • We now automatically synchronize values from st.session_state so that users don't have to call panel.set_value() for input controls like st.number_input and st.text_input (as long as they provide a key).
  • We now provide ni.enum_selectbox that turns any Enum into a dropdown, and handles panel.set_value()
  • We now provide ni.flag_checkboxes that turns any Flags into a set of checkboxes, and handles panel.set_value()
  • The all_types example has been updated to show input controls for supported types, and better show output values for enums and flags.
image
  • The nidaqmx_continuous_analog_input example has been updated so all of the controls are actually functional (except the I/O channel selectors), and to make the layout look more like the LabVIEW version of the example. It also now has a run/stop button, since you have to restart the task to use different settings.
image

Why should this Pull Request be merged?

We want inputs to be as user-friendly as possible.

Finalizes AB#3127262 and fixes AB#3180627

What testing has been done?

Autotests in test_panel_client, test_streamlit_panel, and test_streamlit_panel_accessor.

Manual testing with the all_types example and the nidaqmx_continuous_analog_input example.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 30, 2025

Test Results

   10 files  ±  0     10 suites  ±0   21s ⏱️ +2s
  216 tests + 26    216 ✅ + 26  0 💤 ±0  0 ❌ ±0 
2 110 runs  +260  2 110 ✅ +260  0 💤 ±0  0 ❌ ±0 

Results for commit c7318d6. ± Comparison against base commit 2f3724a.

This pull request removes 10 and adds 36 tests. Note that renamed tests count towards both.
tests.unit.test_streamlit_panel ‑ test___builtin_scalar_type___set_value___gets_same_value[20]
tests.unit.test_streamlit_panel ‑ test___builtin_scalar_type___set_value___gets_same_value[5]
tests.unit.test_streamlit_panel ‑ test___builtin_scalar_type___set_value___gets_same_value[MixinIntEnum.VALUE33]
tests.unit.test_streamlit_panel ‑ test___builtin_scalar_type___set_value___gets_same_value[MyIntEnum.VALUE20]
tests.unit.test_streamlit_panel ‑ test___builtin_scalar_type___set_value___gets_same_value[MyIntFlags.VALUE4|VALUE1]
tests.unit.test_streamlit_panel ‑ test___builtin_scalar_type___set_value___gets_same_value[value11]
tests.unit.test_streamlit_panel ‑ test___builtin_scalar_type___set_value___gets_same_value[value3]
tests.unit.test_streamlit_panel ‑ test___unsupported_type___set_value___raises[MyEnum.VALUE300]
tests.unit.test_streamlit_panel ‑ test___unsupported_type___set_value___raises[MyFlags.VALUE16|VALUE8]
tests.unit.test_streamlit_panel ‑ test___unsupported_type___set_value___raises[MyFlags.VALUE8|VALUE16]
tests.unit.test_streamlit_panel ‑ test___enum_type___set_value___gets_same_value[20]
tests.unit.test_streamlit_panel ‑ test___enum_type___set_value___gets_same_value[5]
tests.unit.test_streamlit_panel ‑ test___enum_type___set_value___gets_same_value[MixinIntEnum.VALUE33]
tests.unit.test_streamlit_panel ‑ test___enum_type___set_value___gets_same_value[MyIntEnum.VALUE20]
tests.unit.test_streamlit_panel ‑ test___enum_type___set_value___gets_same_value[MyIntFlags.VALUE4|VALUE1]
tests.unit.test_streamlit_panel ‑ test___enum_type___set_value___gets_same_value[MyIntableEnum.VALUE200]
tests.unit.test_streamlit_panel ‑ test___enum_type___set_value___gets_same_value[MyIntableFlags.VALUE16|VALUE32]
tests.unit.test_streamlit_panel ‑ test___enum_type___set_value___gets_same_value[MyIntableFlags.VALUE32|VALUE16]
tests.unit.test_streamlit_panel ‑ test___enum_type___set_value___gets_same_value[MyMixedEnum.VALUE2]
tests.unit.test_streamlit_panel ‑ test___enum_type___set_value___gets_same_value[value11]
…

♻️ This comment has been updated with latest results.

@mikeprosserni mikeprosserni requested a review from Copilot July 7, 2025 15:53
Copy link

Copilot AI left a 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 enhances the panel value API to indicate when values are missing, updates clients and tests for this new behavior, and adds first-class support for Enum and Flag controls in Streamlit panels.

  • Introduce a found field in GetValue RPC, update PanelClient.get_value to return (found, value), and adapt StreamlitPanelValueAccessor.get_value to raise KeyError or coerce enums.
  • Extend tests: update the fake servicer, adjust existing exception tests, and add extensive coverage for enum and flag value handling.
  • Add two new Streamlit controls (enum_selectbox, flag_checkboxes), auto-sync session state in panel initializer, and update example scripts to use these controls.

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/utils/_fake_python_panel_servicer.py Return GetValueResponse(found=...) instead of aborting
tests/unit/test_streamlit_panel.py Adjust exception types, add new tests for enum/flag paths
tests/unit/test_panel_client.py Update get_value tests to expect (found, value) tuple
tests/types.py Add new Flag/Enum types to cover expanded support
src/nipanel/_panel_client.py Change get_value to return (bool, object)
src/nipanel/_panel_value_accessor.py Handle (found, value) tuple and enum coercion
src/nipanel/_convert.py Add is_supported_type helper
src/ni/pythonpanel/v1/python_panel_service_pb2* Add found field in protobuf definitions and stubs
src/nipanel/_streamlit_panel_initializer.py Auto-sync session state values into the panel
src/nipanel/controls/_flag_checkboxes.py New control for selecting Flag enums via checkboxes
src/nipanel/controls/_enum_selectbox.py New control for selecting Enum values via a selectbox
examples/nidaqmx/nidaqmx_continuous_analog_input_panel.py Use new controls, session-state sync, layout tweaks
examples/nidaqmx/nidaqmx_continuous_analog_input.py Drive panel values for DAQmx task configuration
examples/all_types/define_types.py & all_types_panel.py Update example to showcase all supported types
Comments suppressed due to low confidence (3)

tests/unit/test_streamlit_panel.py:300

  • This docstring is outdated: the test now covers enum types. Update it to reflect that this test validates enum behavior.
    """Test that set_value() and get_value() work for builtin scalar types."""

tests/types.py:72

  • StrEnum is not imported in this file, causing a NameError. Add from enum import StrEnum or qualify as enum.StrEnum.
class MyStringableEnum(StrEnum):

examples/nidaqmx/nidaqmx_continuous_analog_input_panel.py:55

  • The st.container API does not support a border parameter. Remove border=True or apply supported Streamlit styling instead.
    with st.container(border=True):

@mikeprosserni mikeprosserni marked this pull request as ready for review July 7, 2025 20:09
@mikeprosserni mikeprosserni requested a review from csjall as a code owner July 7, 2025 20:09
@mikeprosserni mikeprosserni requested a review from bkeryan July 7, 2025 20:09
@mikeprosserni mikeprosserni requested a review from bkeryan July 11, 2025 18:18
@mikeprosserni mikeprosserni merged commit 97cdef0 into main Jul 11, 2025
14 checks passed
@mikeprosserni mikeprosserni deleted the users/mprosser/input-improvements branch July 11, 2025 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants