|
| 1 | +"""Streamlit application script for displaying values using nipanel package.""" |
| 2 | +import nipanel |
| 3 | +import streamlit as st |
| 4 | +import streamlit.components.v1 as components |
| 5 | +from streamlit_echarts import st_echarts |
| 6 | + |
| 7 | +panel = nipanel.StreamlitPanelValueAccessor(panel_id="nidaqmx_continuous_analog_input_panel") |
| 8 | + |
| 9 | +add_refresh_component = components.declare_component( |
| 10 | + "panelRefreshComponent", |
| 11 | + url=f"http://localhost:42001/panels/refresh/{panel.panel_id}",) |
| 12 | +add_refresh_component() |
| 13 | + |
| 14 | + |
| 15 | +st.title("Analog Input - Voltage and Thermocouple in a Single Task") |
| 16 | +voltage_tab, thermocouple_tab = st.tabs(["Voltage", "Thermocouple"]) |
| 17 | + |
| 18 | +st.markdown( |
| 19 | + """ |
| 20 | + <style> |
| 21 | + div[data-baseweb="select"] { |
| 22 | + width: 190px !important; /* Adjust the width as needed */ |
| 23 | + } |
| 24 | + </style> |
| 25 | + """, |
| 26 | + unsafe_allow_html=True |
| 27 | +) |
| 28 | + |
| 29 | + |
| 30 | +list_of_therm_amp = panel.get_value("amplitude") |
| 31 | +list_of_voltage_amp = panel.get_value("Volts") |
| 32 | + |
| 33 | +if "therm_history" not in st.session_state: |
| 34 | + st.session_state.therm_history = [] |
| 35 | +if "volts_history" not in st.session_state: |
| 36 | + st.session_state.volts_history = [] |
| 37 | + |
| 38 | +for therm_amp in list_of_therm_amp: |
| 39 | + st.session_state.therm_history.append(therm_amp) |
| 40 | +for voltage_amp in list_of_voltage_amp: |
| 41 | + st.session_state.volts_history.append(voltage_amp) |
| 42 | + |
| 43 | +therm_amp_graph = { |
| 44 | + "tooltip": {"trigger": "axis"}, |
| 45 | + "legend": {"data": ["thermocouple_amplitude"]}, |
| 46 | + "xAxis": { |
| 47 | + "type": "category", |
| 48 | + "data":list(range(len(st.session_state.therm_history))), |
| 49 | + "name": "Time" |
| 50 | + }, |
| 51 | + "yAxis": { |
| 52 | + "type": "value", |
| 53 | + "name": "Thermocouple Amplitude" |
| 54 | + }, |
| 55 | + "series": [ |
| 56 | + { |
| 57 | + "name": "thermocouple_amplitude", |
| 58 | + "type": "line", |
| 59 | + "data": st.session_state.therm_history, |
| 60 | + "color": "red" |
| 61 | + }, |
| 62 | + |
| 63 | + |
| 64 | + ], |
| 65 | +} |
| 66 | +st_echarts(options=therm_amp_graph, height="400px") |
| 67 | + |
| 68 | +voltage_amp_graph = { |
| 69 | + "tooltip": {"trigger": "axis"}, |
| 70 | + "legend": {"data": ["voltage_amplitude"]}, |
| 71 | + "xAxis": { |
| 72 | + "type": "category", |
| 73 | + "data": list(range(len(st.session_state.volts_history))), |
| 74 | + "name": "Time" |
| 75 | + }, |
| 76 | + "yAxis": { |
| 77 | + "type": "value", |
| 78 | + "name": "Voltage Amplitude" |
| 79 | + }, |
| 80 | + "series": [ |
| 81 | + { |
| 82 | + "name": "voltage_amplitude", |
| 83 | + "type": "line", |
| 84 | + "data": st.session_state.volts_history, |
| 85 | + }, |
| 86 | + |
| 87 | + ], |
| 88 | +} |
| 89 | +st_echarts(options=voltage_amp_graph, height="400px") |
| 90 | + |
| 91 | +st.header("Voltage & Thermocouple") |
| 92 | +voltage_therm_graph = { |
| 93 | + "tooltip": {"trigger": "axis"}, |
| 94 | + "legend": {"data": ["voltage_amplitude", "thermocouple_amplitude"]}, |
| 95 | + "xAxis": { |
| 96 | + "type": "category", |
| 97 | + "data": list(range(len(st.session_state.volts_history))), |
| 98 | + "name": "Time" |
| 99 | + }, |
| 100 | + "yAxis": { |
| 101 | + "type": "value", |
| 102 | + "name": "Voltage and Thermocouple Amplitude" |
| 103 | + }, |
| 104 | + "series": [ |
| 105 | + { |
| 106 | + "name": "voltage_amplitude", |
| 107 | + "type": "line", |
| 108 | + "data": st.session_state.volts_history, |
| 109 | + "emphasis": {"focus":"series"}, |
| 110 | + "smooth": True, |
| 111 | + "seriesLayoutBy": "row", |
| 112 | + }, |
| 113 | + { |
| 114 | + "name": "thermocouple_amplitude", |
| 115 | + "type": "line", |
| 116 | + "data": st.session_state.therm_history, |
| 117 | + "color": "red", |
| 118 | + "emphasis": {"focus":"series"}, |
| 119 | + "smooth": True, |
| 120 | + "seriesLayoutBy": "row", |
| 121 | + }, |
| 122 | + ], |
| 123 | +} |
| 124 | +st_echarts(options=voltage_therm_graph, height="400px") |
| 125 | + |
| 126 | +with voltage_tab: |
| 127 | + left_volt_tab, center_volt_tab, right_volt_tab = st.columns(3) |
| 128 | + with left_volt_tab: |
| 129 | + st.selectbox(options=["Mod1/ai2"], label="Physical Channels", disabled=True) |
| 130 | + st.selectbox(options=["Off"], label="Logging Modes", disabled=False) |
| 131 | + with center_volt_tab: |
| 132 | + st.selectbox(options=["-5"],label="Min Value") |
| 133 | + st.selectbox(options=["5"],label="Max Value") |
| 134 | + st.selectbox(options=["1000"], label="Samples per Loops", disabled=False) |
| 135 | + with right_volt_tab: |
| 136 | + st.selectbox(options=["default"], label="Terminal Configurations") |
| 137 | + st.selectbox(options=["OnboardClock"], label="Sample Clock Sources", disabled=False) |
| 138 | + |
| 139 | + |
| 140 | +thermocouple_tab.header("Thermocouple") |
| 141 | +with thermocouple_tab: |
| 142 | + left, middle, right = st.columns(3) |
| 143 | + with left: |
| 144 | + st.selectbox(options=["Mod1/ai3"], label="Physical Channel", disabled=True) |
| 145 | + st.selectbox(options=["0"], label="Min", disabled=False) |
| 146 | + st.selectbox(options=["100"], label="Max", disabled=False) |
| 147 | + st.selectbox(options=["Off"], label="Logging Mode", disabled=False) |
| 148 | + |
| 149 | + with middle: |
| 150 | + st.selectbox(options=["Deg C"], label = "Units", disabled=False) |
| 151 | + st.selectbox(options=["J"], label="Thermocouple Type", disabled=False) |
| 152 | + st.selectbox(options=["Constant Value"], label="CJC Source", disabled=False) |
| 153 | + st.selectbox(options=["1000"], label="Samples per Loop", disabled=False) |
| 154 | + with right: |
| 155 | + st.selectbox(options=["25"],label="CJC Value", disabled=False) |
| 156 | + st.selectbox(options=["OnboardClock"], label="Sample Clock Source", disabled=False) |
| 157 | + st.selectbox(options=[" "], label="Actual Sample Rate", disabled=True) |
| 158 | + |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | + |
0 commit comments