Skip to content

Commit c3dad08

Browse files
Mike ProsserMike Prosser
authored andcommitted
change sample to hello, and address other feedback
1 parent 0d3aa3c commit c3dad08

File tree

10 files changed

+49
-66
lines changed

10 files changed

+49
-66
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ start docs\_build\index.html
5757
## Running examples
5858

5959
1. First, run the PythonPanelService (not part of this repo, provided seperately)
60-
2. Run the command `poetry run python examples/sample/sample.py`
61-
3. Open http://localhost:42001/panel-service/panels/sample_panel/ in your browser
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
6262
4. If there is an error about missing imports (especially nipanel), execute this
63-
command to install the dependencies into the venv: `C:\Users\mprosser\AppData\Local\Temp\python_panel_service_venv\Scripts\python.exe
64-
-m pip install C:\dev\fireserp\nipanel-python[examples,dev]`, then restart the PythonPanelService and re-run sample.py.
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.
6566

6667
You can see all running panels (and stop them) at: http://localhost:42001/panel-service/
6768

examples/hello/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Hello
2+
3+
This is a simple nipanel example that displays a Streamlit app.
4+
5+
### Feature
6+
7+
- Just a Hello World
8+
9+
### Required Software
10+
11+
- Python 3.9 or later
12+
13+
### Usage
14+
15+
Run `poetry run python examples/hello/hello.py`

examples/hello/hello.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""This example demonstrates how to open/update a Streamlit application using nipanel package."""
2+
3+
from pathlib import Path
4+
5+
import nipanel
6+
7+
panel_script_path = Path(__file__).with_name("hello_panel.py")
8+
panel = nipanel.create_panel(panel_script_path)
9+
10+
panel.set_value("hello_string", "Hello, World!")
11+
12+
print(f"Panel URL: {panel.panel_url}")

examples/hello/hello_panel.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""A Streamlit visualization panel for the hello.py example script."""
2+
3+
import streamlit as st
4+
5+
import nipanel
6+
7+
panel = nipanel.get_panel_accessor()
8+
9+
st.set_page_config(page_title="Hello World Example", page_icon="📊", layout="wide")
10+
st.title("Hello World Example")
11+
st.write(panel.get_value("hello_string", ""))

examples/sample/README.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

examples/sample/sample.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/sample/sample_panel.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

examples/simple_graph/simple_graph_panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Example of displaying a sine wave using streamlit-echarts in a nipanel."""
1+
"""A Streamlit visualization panel for the simple_graph.py example script."""
22

33
import streamlit as st
44
from streamlit_echarts import st_echarts # type: ignore

src/nipanel/_streamlit_panel_initializer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ def create_panel(streamlit_script_path: Path) -> StreamlitPanel:
3232
"nipanel.create_panel() should not be called from a Streamlit script. Call nipanel.get_panel_accessor() instead."
3333
)
3434

35-
path_str = str(streamlit_script_path)
36-
if not path_str.endswith(".py"):
35+
if streamlit_script_path.suffix != ".py":
3736
raise ValueError(
3837
"The provided script path must be a valid Streamlit script ending with '.py'."
3938
)
4039

4140
panel_id = streamlit_script_path.stem
41+
path_str = str(streamlit_script_path)
4242
return StreamlitPanel(panel_id, path_str)
4343

4444

src/nipanel/converters/protobuf_types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Classes to convert between measurement specific protobuf types and containers."""
22

3+
from __future__ import annotations
4+
35
import collections.abc
46
import datetime as dt
57
from typing import Type, Union
@@ -100,7 +102,7 @@ def _value_to_attribute(self, value: ExtendedPropertyValue) -> WaveformAttribute
100102
def to_python_value(self, protobuf_message: DoubleAnalogWaveform) -> AnalogWaveform[np.float64]:
101103
"""Convert the protobuf DoubleAnalogWaveform to a Python AnalogWaveform."""
102104
# Declare timing to accept both bintime and dt.datetime to satisfy mypy.
103-
timing: Timing[Union[bt.DateTime, dt.datetime]]
105+
timing: Timing[bt.DateTime | dt.datetime]
104106
if not protobuf_message.dt and not protobuf_message.HasField("t0"):
105107
# If both dt and t0 are unset, use Timing.empty.
106108
timing = Timing.empty

0 commit comments

Comments
 (0)