Skip to content

Commit 51e133d

Browse files
Mike ProsserMike Prosser
authored andcommitted
Add more streamlit control examples to all_types_panel and fix selectboxes in nidaq example
1 parent b861029 commit 51e133d

File tree

2 files changed

+96
-10
lines changed

2 files changed

+96
-10
lines changed

examples/all_types/all_types_panel.py

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,97 @@
1313
st.title("All Types Example")
1414

1515
panel = nipanel.get_streamlit_panel_accessor()
16+
17+
col1, col2, col3 = st.columns([0.2, 0.2, 0.6])
18+
with col1:
19+
st.header("Control or Type")
20+
with col2:
21+
st.header("Input")
22+
with col3:
23+
st.header("Output")
24+
25+
st.markdown("---")
26+
col1, col2, col3 = st.columns([0.2, 0.2, 0.6])
27+
with col1:
28+
st.write("st.selectbox")
29+
with col2:
30+
st.selectbox(
31+
label="string",
32+
options=["Option 1", "Option 2", "Option 3", "Option 4"],
33+
key="example_selectbox",
34+
)
35+
with col3:
36+
st.write(panel.get_value("example_selectbox", ""))
37+
38+
st.markdown("---")
39+
col1, col2, col3 = st.columns([0.2, 0.2, 0.6])
40+
with col1:
41+
st.write("st.slider & st.progress")
42+
with col2:
43+
st.slider(
44+
label="int",
45+
min_value=0,
46+
max_value=100,
47+
value=50,
48+
key="example_slider",
49+
)
50+
with col3:
51+
progress = panel.get_value("example_slider", 50)
52+
st.progress(progress / 100, text=f"{progress}%")
53+
54+
55+
st.markdown("---")
56+
col1, col2, col3 = st.columns([0.2, 0.2, 0.6])
57+
with col1:
58+
st.write("st.color_picker")
59+
with col2:
60+
st.color_picker(
61+
label="color",
62+
value="#000000",
63+
key="example_color_picker",
64+
)
65+
with col3:
66+
color = panel.get_value("example_color_picker", "#000000")
67+
st.write(color)
68+
st.markdown(
69+
f"<div style='width:40px; height:20px; background:{color}; border:1px solid #888;'></div>",
70+
unsafe_allow_html=True,
71+
)
72+
73+
st.markdown("---")
74+
col1, col2, col3 = st.columns([0.2, 0.2, 0.6])
75+
with col1:
76+
st.write("st.multiselect")
77+
with col2:
78+
st.multiselect(
79+
label="list of strings",
80+
options=["Option A", "Option B", "Option C", "Option D"],
81+
default=["Option A"],
82+
key="example_multiselect",
83+
)
84+
with col3:
85+
st.write(panel.get_value("example_multiselect", ["Option A"]))
86+
87+
st.markdown("---")
88+
col1, col2, col3 = st.columns([0.2, 0.2, 0.6])
89+
with col1:
90+
st.write("st.radio")
91+
with col2:
92+
st.radio(
93+
label="string",
94+
options=["Choice 1", "Choice 2", "Choice 3"],
95+
index=0,
96+
key="example_radio",
97+
)
98+
with col3:
99+
st.write(panel.get_value("example_radio", "Choice 1"))
100+
16101
for name in all_types_with_values.keys():
17102
st.markdown("---")
18103

19104
default_value = all_types_with_values[name]
20-
col1, col2, col3 = st.columns([0.2, 0.2, 0.6])
21105

106+
col1, col2, col3 = st.columns([0.2, 0.2, 0.6])
22107
with col1:
23108
st.write(name)
24109

examples/nidaqmx/nidaqmx_analog_input_filtering/nidaqmx_analog_input_filtering_panel.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@
5757
f"There was an error running the script. Fix the issue and re-run nidaqmx_analog_input_filtering.py \n\n {panel.get_value('daq_error', '')}"
5858
)
5959
st.title("Channel Settings")
60-
physical_channel = st.selectbox(
60+
st.selectbox(
6161
options=panel.get_value("available_channel_names", ["Mod2/ai0"]),
6262
index=0,
6363
label="Physical Channels",
6464
disabled=panel.get_value("is_running", False),
65+
key="physical_channel",
6566
)
66-
panel.set_value("physical_channel", physical_channel)
6767
enum_selectbox(
6868
panel,
6969
label="Terminal Configuration",
@@ -74,13 +74,13 @@
7474

7575
st.title("Timing Settings")
7676

77-
source = st.selectbox(
77+
st.selectbox(
7878
"Sample Clock Source",
7979
options=panel.get_value("available_trigger_sources", [""]),
8080
index=0,
8181
disabled=panel.get_value("is_running", False),
82+
key="source",
8283
)
83-
panel.set_value("source", source)
8484
st.number_input(
8585
"Sample Rate",
8686
value=1000.0,
@@ -106,12 +106,12 @@
106106
)
107107
st.title("Filtering Settings")
108108

109-
filter = st.selectbox(
109+
st.selectbox(
110110
"Filter",
111111
options=["No Filtering", "Filter"],
112112
disabled=panel.get_value("is_running", False),
113+
key="filter",
113114
)
114-
panel.set_value("filter", filter)
115115
enum_selectbox(
116116
panel,
117117
label="Filter Response",
@@ -203,10 +203,11 @@
203203
)
204204
if trigger_type == "2":
205205
with st.container(border=True):
206-
source = st.selectbox(
207-
"Source", options=panel.get_value("available_trigger_sources", [""])
206+
st.selectbox(
207+
"Source",
208+
options=panel.get_value("available_trigger_sources", [""]),
209+
key="digital_source",
208210
)
209-
panel.set_value("digital_source", source)
210211
enum_selectbox(
211212
panel,
212213
label="Edge",

0 commit comments

Comments
 (0)