-
Notifications
You must be signed in to change notification settings - Fork 0
Add more samples, to make testing with multiple panels easier. #69
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1d6d62e
Add more samples, to make testing with multiple panels easier.
dc30594
Merge remote-tracking branch 'origin/main' into users/mprosser/add-mo…
4c1483e
use nipanel.initialize_panel()
f259379
Merge remote-tracking branch 'origin/main' into users/mprosser/add-mo…
6f6c683
all_types example (from placeholder)
81a4c57
Merge remote-tracking branch 'origin/main' into users/mprosser/add-mo…
d3a1df8
add nitypes to all_types, and update comments
9526a40
added simple graph example
59ac9d9
fix mypy issues and move streamlit-echarts to examples dependancy group
3d60ea7
fix lock file and add titles and icons to the panel tabs
0d3aa3c
rename initialize_panel to get_panel_accessor and throw exceptions wh…
c3dad08
change sample to hello, and address other feedback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| ## All Types Example | ||
|
|
||
| This is an example for `nipanel` that demonstrates all supported data types | ||
|
|
||
| ### Feature | ||
|
|
||
| - Demonstrates support for all data types | ||
|
|
||
| ### Required Software | ||
|
|
||
| - Python 3.9 or later | ||
|
|
||
| ### Usage | ||
|
|
||
| Run `poetry run examples/all_types/all_types.py` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| """An example that demonstrates the supported data types for nipanel scripts.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from define_types import all_types_with_values | ||
|
|
||
| import nipanel | ||
|
|
||
| panel_script_path = Path(__file__).with_name("all_types_panel.py") | ||
| panel = nipanel.create_panel(panel_script_path) | ||
|
|
||
| print("Setting values") | ||
| for name, value in all_types_with_values.items(): | ||
| print(f"{name:>15} {value}") | ||
| panel.set_value(name, value) | ||
|
|
||
| print() | ||
| print("Getting values") | ||
| for name in all_types_with_values.keys(): | ||
| the_value = panel.get_value(name) | ||
| print(f"{name:>20} {the_value}") | ||
|
|
||
| print(f"Panel URL: {panel.panel_url}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| """A Streamlit visualization panel for the all_types.py example script.""" | ||
|
|
||
| import streamlit as st | ||
| from define_types import all_types_with_values | ||
|
|
||
| import nipanel | ||
|
|
||
| panel = nipanel.initialize_panel() | ||
|
|
||
| st.title("All Types") | ||
|
|
||
| for name in all_types_with_values.keys(): | ||
| col1, col2 = st.columns([0.4, 0.6]) | ||
|
|
||
| with col1: | ||
| st.write(name) | ||
|
|
||
| with col2: | ||
| st.write(panel.get_value(name)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| """Define types.""" | ||
|
|
||
| import enum | ||
|
|
||
| import numpy as np | ||
| from nitypes.scalar import Scalar | ||
| from nitypes.waveform import AnalogWaveform | ||
|
|
||
|
|
||
| class MyIntFlags(enum.IntFlag): | ||
| """Example of an IntFlag enum.""" | ||
|
|
||
| VALUE1 = 1 | ||
| VALUE2 = 2 | ||
| VALUE4 = 4 | ||
|
|
||
|
|
||
| class MyIntEnum(enum.IntEnum): | ||
| """Example of an IntEnum enum.""" | ||
|
|
||
| VALUE10 = 10 | ||
| VALUE20 = 20 | ||
| VALUE30 = 30 | ||
|
|
||
|
|
||
| class MyStrEnum(str, enum.Enum): | ||
| """Example of a mixin string enum.""" | ||
|
|
||
| VALUE1 = "value1" | ||
| VALUE2 = "value2" | ||
| VALUE3 = "value3" | ||
|
|
||
|
|
||
| all_types_with_values = { | ||
| # supported scalar types | ||
| "bool": True, | ||
| "bytes": b"robotext", | ||
| "float": 13.12, | ||
| "int": 42, | ||
| "str": "sample string", | ||
| # supported collection types | ||
| "bool_collection": [True, False, True], | ||
| "bytes_collection": [b"one", b"two", b"three"], | ||
| "float_collection": [1.1, 2.2, 3.3], | ||
| "int_collection": [1, 2, 3], | ||
| "str_collection": ["one", "two", "three"], | ||
| # supported enum and flag types | ||
| "intflags": MyIntFlags.VALUE1 | MyIntFlags.VALUE4, | ||
| "intenum": MyIntEnum.VALUE20, | ||
| "strenum": MyStrEnum.VALUE3, | ||
| "intflags_collection": [MyIntFlags.VALUE1, MyIntFlags.VALUE2, MyIntFlags.VALUE4], | ||
| "intenum_collection": [MyIntEnum.VALUE10, MyIntEnum.VALUE20, MyIntEnum.VALUE30], | ||
| "strenum_collection": [MyStrEnum.VALUE1, MyStrEnum.VALUE2, MyStrEnum.VALUE3], | ||
| # supported collections | ||
| "list": [1, 2, 3], | ||
| "tuple": (4, 5, 6), | ||
| "set": {7, 8, 9}, | ||
| "frozenset": frozenset([10, 11, 12]), | ||
| # NI types | ||
| "nitypes_Scalar": Scalar(42, "m"), | ||
| "nitypes_AnalogWaveform": AnalogWaveform.from_array_1d(np.array([1.0, 2.0, 3.0])), | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Simple Graph Example | ||
|
|
||
| This example demonstrates using nipanel with Streamlit to display a dynamic sine wave using the `streamlit-echarts` library. | ||
|
|
||
| ## Features | ||
|
|
||
| - Generates sine wave data with varying frequency | ||
| - Displays the data in an interactive chart using ECharts | ||
| - Updates automatically every 1 second | ||
| - Shows statistics about the displayed data | ||
|
|
||
| ### Required Software | ||
|
|
||
| - Python 3.9 or later | ||
|
|
||
| ### Usage | ||
|
|
||
| Run `poetry run examples/simple_graph/simple_graph.py` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| """Example of using nipanel to display a sine wave graph using st_echarts.""" | ||
|
|
||
| import math | ||
| import time | ||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
|
|
||
| import nipanel | ||
|
|
||
|
|
||
| panel_script_path = Path(__file__).with_name("simple_graph_panel.py") | ||
| panel = nipanel.create_panel(panel_script_path) | ||
|
|
||
| amplitude = 1.0 | ||
| frequency = 1.0 | ||
| num_points = 100 | ||
|
|
||
| try: | ||
| print(f"Panel URL: {panel.panel_url}") | ||
| print("Press Ctrl+C to exit") | ||
|
|
||
| # Generate and update the sine wave data periodically | ||
| while True: | ||
| time_points = np.linspace(0, num_points, num_points) | ||
| sine_values = amplitude * np.sin(frequency * time_points) | ||
|
|
||
| panel.set_value("time_points", time_points.tolist()) | ||
| panel.set_value("sine_values", sine_values.tolist()) | ||
| panel.set_value("amplitude", amplitude) | ||
| panel.set_value("frequency", frequency) | ||
|
|
||
| # Slowly vary the frequency for a more dynamic visualization | ||
| frequency = 1.0 + 0.5 * math.sin(time.time() / 5.0) | ||
| time.sleep(1) | ||
|
|
||
| except KeyboardInterrupt: | ||
| print("Exiting...") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| """Example of displaying a sine wave using streamlit-echarts in a nipanel.""" | ||
|
|
||
| import streamlit as st | ||
| from streamlit_echarts import st_echarts | ||
|
|
||
| from nipanel import initialize_panel | ||
|
|
||
|
|
||
| st.set_page_config(page_title="Simple Graph Example", page_icon="📈", layout="wide") | ||
| st.title("Simple Sine Wave Visualization") | ||
|
|
||
| panel = initialize_panel() | ||
| time_points = panel.get_value("time_points", [0.0]) | ||
| sine_values = panel.get_value("sine_values", [0.0]) | ||
| amplitude = panel.get_value("amplitude", 1.0) | ||
| frequency = panel.get_value("frequency", 1.0) | ||
|
|
||
| col1, col2, col3, col4, col5 = st.columns(5) | ||
| with col1: | ||
| st.metric("Amplitude", f"{amplitude:.2f}") | ||
| with col2: | ||
| st.metric("Frequency", f"{frequency:.2f} Hz") | ||
| with col3: | ||
| st.metric("Min Value", f"{min(sine_values):.3f}") | ||
| with col4: | ||
| st.metric("Max Value", f"{max(sine_values):.3f}") | ||
| with col5: | ||
| st.metric("Data Points", len(sine_values)) | ||
|
|
||
| # Prepare data for echarts | ||
| data = [{"value": [x, y]} for x, y in zip(time_points, sine_values)] | ||
|
|
||
| # Configure the chart options | ||
| options = { | ||
| "animation": False, # Disable animation for smoother updates | ||
| "title": {"text": "Sine Wave"}, | ||
| "tooltip": {"trigger": "axis"}, | ||
| "xAxis": {"type": "value", "name": "Time (s)", "nameLocation": "middle", "nameGap": 30}, | ||
| "yAxis": { | ||
| "type": "value", | ||
| "name": "Amplitude", | ||
| "nameLocation": "middle", | ||
| "nameGap": 30, | ||
| }, | ||
| "series": [ | ||
| { | ||
| "data": data, | ||
| "type": "line", | ||
| "showSymbol": True, | ||
| "smooth": True, | ||
| "lineStyle": {"width": 2, "color": "#1f77b4"}, | ||
| "areaStyle": {"color": "#1f77b4", "opacity": 0.3}, | ||
| "name": "Sine Wave", | ||
| } | ||
| ], | ||
| } | ||
|
|
||
| # Display the chart | ||
| st_echarts(options=options, height="400px") |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.