Skip to content

Commit 6f6c683

Browse files
Mike ProsserMike Prosser
authored andcommitted
all_types example (from placeholder)
1 parent f259379 commit 6f6c683

File tree

12 files changed

+148
-139
lines changed

12 files changed

+148
-139
lines changed

examples/all_types/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## All Types Example
2+
3+
This is a nipanel example that demonstrates all supported data types
4+
5+
### Feature
6+
7+
- Demonstrates support for all data types
8+
9+
### Required Software
10+
11+
- Python 3.9 or later
12+
13+
### Usage
14+
15+
Run `poetry run examples/all_types/all_types.py`

examples/all_types/all_types.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""example script for nipanel package demonstrating various data types."""
2+
3+
from pathlib import Path
4+
5+
from define_types import all_types_with_values
6+
7+
import nipanel
8+
9+
panel_script_path = Path(__file__).with_name("all_types_panel.py")
10+
panel = nipanel.create_panel(panel_script_path)
11+
12+
print("Setting values")
13+
for name, value in all_types_with_values.items():
14+
print(f"{name:>15} {value}")
15+
panel.set_value(name, value)
16+
17+
print()
18+
print("Getting values")
19+
for name in all_types_with_values.keys():
20+
the_value = panel.get_value(name)
21+
print(f"{name:>20} {the_value}")
22+
23+
print(f"Panel URL: {panel.panel_url}")
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""A Streamlit panel to demonstrate various types and their values."""
2+
3+
import streamlit as st
4+
from define_types import all_types_with_values
5+
6+
import nipanel
7+
8+
panel = nipanel.initialize_panel()
9+
10+
st.title("All Types")
11+
12+
for name in all_types_with_values.keys():
13+
col1, col2 = st.columns([0.4, 0.6])
14+
15+
with col1:
16+
st.write(name)
17+
18+
with col2:
19+
st.write(panel.get_value(name))

examples/all_types/define_types.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""Define types."""
2+
3+
import enum
4+
5+
6+
class MyIntFlags(enum.IntFlag):
7+
"""Example of an IntFlag enum."""
8+
9+
VALUE1 = 1
10+
VALUE2 = 2
11+
VALUE4 = 4
12+
13+
14+
class MyIntEnum(enum.IntEnum):
15+
"""Example of an IntEnum enum."""
16+
17+
VALUE10 = 10
18+
VALUE20 = 20
19+
VALUE30 = 30
20+
21+
22+
class MyStrEnum(str, enum.Enum):
23+
"""Example of a mixin string enum."""
24+
25+
VALUE1 = "value1"
26+
VALUE2 = "value2"
27+
VALUE3 = "value3"
28+
29+
30+
all_types_with_values = {
31+
# supported scalar types
32+
"bool_scalar": True,
33+
"bytes_scalar": b"robotext",
34+
"float_scalar": 13.12,
35+
"int_scalar": 42,
36+
"str_scalar": "sample string",
37+
# supported collection types
38+
"bool_collection": [True, False, True],
39+
"bytes_collection": [b"one", b"two", b"three"],
40+
"float_collection": [1.1, 2.2, 3.3],
41+
"int_collection": [1, 2, 3],
42+
"str_collection": ["one", "two", "three"],
43+
# supported enum and flag types
44+
"intflags_scalar": MyIntFlags.VALUE1 | MyIntFlags.VALUE4,
45+
"intenum_scalar": MyIntEnum.VALUE20,
46+
"strenum_scalar": MyStrEnum.VALUE3,
47+
"intflags_collection": [MyIntFlags.VALUE1, MyIntFlags.VALUE2, MyIntFlags.VALUE4],
48+
"intenum_collection": [MyIntEnum.VALUE10, MyIntEnum.VALUE20, MyIntEnum.VALUE30],
49+
"strenum_collection": [MyStrEnum.VALUE1, MyStrEnum.VALUE2, MyStrEnum.VALUE3],
50+
# supported collections
51+
"list": [1, 2, 3],
52+
"tuple": (4, 5, 6),
53+
"set": {7, 8, 9},
54+
"frozenset": frozenset([10, 11, 12]),
55+
}

examples/placeholder.py

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

examples/sample/sample.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
"""This example demonstrates how to open/update a Streamlit application using nipanel package."""
22

3-
import pathlib
3+
from pathlib import Path
44

55
import nipanel
66

7-
script_path = pathlib.Path(__file__)
8-
panel_script_path = str(script_path.with_name("sample_panel.py"))
7+
panel_script_path = Path(__file__).with_name("sample_panel.py")
8+
panel = nipanel.create_panel(panel_script_path)
99

10-
panel = nipanel.StreamlitPanel(
11-
panel_id="sample_panel",
12-
streamlit_script_path=panel_script_path,
13-
)
1410
panel.set_value("sample_string", "Hello, World!")
1511
panel.set_value("sample_int", 42)
1612
panel.set_value("sample_float", 3.14)

examples/sample/sample_2.py

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

examples/sample/sample_3.py

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

examples/sample/sample_panel_2.py

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

examples/sample/sample_panel_3.py

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

0 commit comments

Comments
 (0)