Skip to content

Commit 0cb6e3f

Browse files
Mike ProsserMike Prosser
authored andcommitted
add panel_id input to create_streamlit_panel()
1 parent c541c34 commit 0cb6e3f

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

examples/performance_checker/performance_checker_panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
def profile_get_value(
16-
panel: "nipanel.StreamlitPanelValueAccessor",
16+
panel: "nipanel.PanelValueAccessor",
1717
value_id: str,
1818
default_value: Any = None,
1919
num_runs: int = 5,

src/nipanel/_streamlit_panel_initializer.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@
1212
PANEL_ACCESSOR_KEY = "StreamlitPanelValueAccessor"
1313

1414

15-
def create_streamlit_panel(streamlit_script_path: Path) -> StreamlitPanel:
15+
def create_streamlit_panel(streamlit_script_path: Path, panel_id: str = "") -> StreamlitPanel:
1616
"""Create a Streamlit panel with the specified script path.
1717
18-
This function initializes a Streamlit panel using the provided script path. It derives the panel
19-
ID from the script's path, which it expects to be a valid Streamlit script. For example, if the
20-
value for streamlit_script_path is "c:/example/some_example.py", then the panel's ID becomes
21-
"some_example".
18+
This function initializes a Streamlit panel using the provided script path. By default, it
19+
derives the panel ID from the script's path, which it expects to be a valid Streamlit script.
20+
For example, if the value for streamlit_script_path is "c:/example/some_example.py", then the
21+
panel's ID becomes "some_example". Alternatively, you can specify a custom panel_id.
2222
2323
Use this function when you want to create a new panel instance to use in a Streamlit
2424
application. Do not call this function from within a Streamlit script.
2525
2626
Args:
2727
streamlit_script_path: The file path of the Streamlit script to be used for the panel.
28+
panel_id: Optional custom panel ID. If not provided, it will be derived from the script
29+
path.
2830
2931
Returns:
3032
A StreamlitPanel instance initialized with the given panel ID.
@@ -39,7 +41,9 @@ def create_streamlit_panel(streamlit_script_path: Path) -> StreamlitPanel:
3941
"The provided script path must be a valid Streamlit script ending with '.py'."
4042
)
4143

42-
panel_id = streamlit_script_path.stem
44+
if panel_id == "":
45+
panel_id = streamlit_script_path.stem
46+
4347
path_str = str(streamlit_script_path)
4448
return StreamlitPanel(panel_id, path_str)
4549

0 commit comments

Comments
 (0)