Skip to content

Commit 2b1d60d

Browse files
mikeprosserniMike Prosser
andauthored
Use the measurement script's environment for the streamlit script (#98)
* pass the python path into the panel client * fix tests * rework streamlit and numpy deps to work better with python 3.9 * clean up daqmx example * cleanup * Joe's feedback (documentation and comments) * add checks to _get_python_path() * update _get_python_path to work better on linux --------- Co-authored-by: Mike Prosser <Mike.Prosser@emerson.com>
1 parent 1727616 commit 2b1d60d

16 files changed

+288
-222
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@ start docs\_build\index.html
5656

5757
## Running examples
5858

59-
1. First, run the PythonPanelService (not part of this repo, provided seperately)
60-
2. Run the command `poetry run python examples/hello/hello.py`
61-
3. Open http://localhost:42001/panel-service/panels/hello_panel/ in your browser
62-
4. If there is an error about missing imports (especially nipanel), execute this
63-
command (from the nipanel-python directory) to install the dependencies into the venv:
64-
`%localappdata%\Temp\python_panel_service_venv\Scripts\python.exe -m pip install .\[examples,dev]`,
65-
then restart the PythonPanelService and re-run hello.py.
66-
67-
You can see all running panels (and stop them) at: http://localhost:42001/panel-service/
59+
1. Run the **PythonPanelService** (not part of this repo, provided seperately)
60+
2. `poetry install --with examples` to get the dependencies needed for the examples
61+
3. Run the examples with these command(s):
62+
- `poetry run python examples/hello/hello.py`
63+
- `poetry run python examples/all_types/all_types.py`
64+
- `poetry run python examples/simple_graph/simple_graph.py`
65+
- `poetry run python examples/nidaqmx/nidaqmx_continuous_analog_input.py` (requires real or simulated devices)
66+
4. Open http://localhost:42001/panel-service/ in your browser, which will show all running panels
6867

6968
# Debugging on the streamlit side
7069

examples/all_types/all_types_panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
import nipanel
77

8-
panel = nipanel.get_panel_accessor()
98

109
st.set_page_config(page_title="All Types Example", page_icon="📊", layout="wide")
1110
st.title("All Types Example")
1211

12+
panel = nipanel.get_panel_accessor()
1313
for name in all_types_with_values.keys():
1414
col1, col2 = st.columns([0.4, 0.6])
1515

examples/hello/hello_panel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
import nipanel
66

7-
panel = nipanel.get_panel_accessor()
87

98
st.set_page_config(page_title="Hello World Example", page_icon="📊", layout="wide")
109
st.title("Hello World Example")
10+
11+
panel = nipanel.get_panel_accessor()
1112
st.write(panel.get_value("hello_string", ""))

examples/nidaqmx/nidaqmx_continuous_analog_input.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
panel_script_path = Path(__file__).with_name("nidaqmx_continuous_analog_input_panel.py")
1111
panel = nipanel.create_panel(panel_script_path)
1212

13+
# How to use nidaqmx: https://nidaqmx-python.readthedocs.io/en/stable/
1314
with nidaqmx.Task() as task:
1415
task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
1516
task.ai_channels.add_ai_thrmcpl_chan("Dev1/ai1")
@@ -18,10 +19,13 @@
1819
)
1920
panel.set_value("sample_rate", task._timing.samp_clk_rate)
2021
task.start()
22+
print(f"Panel URL: {panel.panel_url}")
2123
try:
22-
print(f"\nPress Ctrl + C to stop")
24+
print(f"Press Ctrl + C to stop")
2325
while True:
24-
data = task.read(number_of_samples_per_channel=1000)
26+
data = task.read(
27+
number_of_samples_per_channel=1000 # pyright: ignore[reportArgumentType]
28+
)
2529
panel.set_value("voltage_data", data[0])
2630
panel.set_value("thermocouple_data", data[1])
2731
except KeyboardInterrupt:

examples/nidaqmx/nidaqmx_continuous_analog_input_panel.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import nipanel
77

8-
panel = nipanel.get_panel_accessor()
98

9+
st.set_page_config(page_title="NI-DAQmx Example", page_icon="📈", layout="wide")
1010
st.title("Analog Input - Voltage and Thermocouple in a Single Task")
1111
voltage_tab, thermocouple_tab = st.tabs(["Voltage", "Thermocouple"])
1212

@@ -21,13 +21,15 @@
2121
unsafe_allow_html=True,
2222
)
2323

24+
panel = nipanel.get_panel_accessor()
2425
thermocouple_data = panel.get_value("thermocouple_data", [0.0])
2526
voltage_data = panel.get_value("voltage_data", [0.0])
2627

27-
sample_rate = panel.get_value("sample_rate", 0)
28+
sample_rate = panel.get_value("sample_rate", 0.0)
2829

2930
st.header("Voltage & Thermocouple")
3031
voltage_therm_graph = {
32+
"animation": False,
3133
"tooltip": {"trigger": "axis"},
3234
"legend": {"data": ["Voltage (V)", "Temperature (C)"]},
3335
"xAxis": {
@@ -64,7 +66,7 @@
6466
},
6567
],
6668
}
67-
st_echarts(options=voltage_therm_graph, height="400px")
69+
st_echarts(options=voltage_therm_graph, height="400px", key="voltage_therm_graph")
6870

6971
voltage_tab.header("Voltage")
7072
with voltage_tab:

examples/simple_graph/simple_graph_panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
import nipanel
77

8-
panel = nipanel.get_panel_accessor()
98

109
st.set_page_config(page_title="Simple Graph Example", page_icon="📈", layout="wide")
1110
st.title("Simple Graph Example")
1211

12+
panel = nipanel.get_panel_accessor()
1313
time_points = panel.get_value("time_points", [0.0])
1414
sine_values = panel.get_value("sine_values", [0.0])
1515
amplitude = panel.get_value("amplitude", 1.0)

poetry.lock

Lines changed: 165 additions & 170 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/ni/pythonpanel/v1/python_panel_service.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ message StartPanelRequest {
4949

5050
// Absolute path of the panel script's file on disk, or network path to the file
5151
string panel_script_path = 2;
52+
53+
// Path to the python interpreter to use for the panel script.
54+
string python_path = 3;
5255
}
5356

5457
message StartPanelResponse {

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ protobuf = {version=">=4.21"}
1313
ni-measurement-plugin-sdk = {version=">=2.3"}
1414
typing-extensions = ">=4.13.2"
1515
streamlit = ">=1.24"
16-
streamlit-echarts = ">=0.4.0"
1716
nitypes = {version=">=0.1.0dev2", allow-prereleases=true}
17+
numpy = [
18+
{version=">=1.20.0,<2.0.0", python=">=3.9,<3.10"},
19+
{version=">=2.0.0", python=">=3.10"}
20+
]
1821
debugpy = ">=1.8.1"
1922

2023
[tool.poetry.group.dev.dependencies]

src/ni/pythonpanel/v1/python_panel_service_pb2.py

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)