@@ -19,14 +19,19 @@ def create_panel(streamlit_script_path: Path) -> StreamlitPanel:
1919 "some_example".
2020
2121 Use this function when you want to create a new panel instance to use in a Streamlit
22- application.
22+ application. Do not call this function from within a Streamlit script.
2323
2424 Args:
2525 streamlit_script_path: The file path of the Streamlit script to be used for the panel.
2626
2727 Returns:
2828 A StreamlitPanel instance initialized with the given panel ID.
2929 """
30+ if st .get_option ("server.baseUrlPath" ) != "" :
31+ raise RuntimeError (
32+ "nipanel.create_panel() should not be called from a Streamlit script. Call nipanel.get_panel_accessor() instead."
33+ )
34+
3035 path_str = str (streamlit_script_path )
3136 if not path_str .endswith (".py" ):
3237 raise ValueError (
@@ -37,17 +42,21 @@ def create_panel(streamlit_script_path: Path) -> StreamlitPanel:
3742 return StreamlitPanel (panel_id , path_str )
3843
3944
40- def initialize_panel () -> StreamlitPanelValueAccessor :
45+ def get_panel_accessor () -> StreamlitPanelValueAccessor :
4146 """Initialize and return the Streamlit panel value accessor.
4247
4348 This function retrieves the Streamlit panel value accessor for the current Streamlit script.
44- It is typically used within a Streamlit script to access and manipulate panel values.
45- The accessor will be cached in the Streamlit session state to ensure that it is reused across
46- reruns of the script.
49+ This function should only be called from within a Streamlit script. The accessor will be cached
50+ in the Streamlit session state to ensure that it is reused across reruns of the script.
4751
4852 Returns:
4953 A StreamlitPanelValueAccessor instance for the current panel.
5054 """
55+ if st .get_option ("server.baseUrlPath" ) == "" :
56+ raise RuntimeError (
57+ "nipanel.get_panel_accessor() should only be called from a Streamlit script. Call nipanel.create_panel() instead."
58+ )
59+
5160 if PANEL_ACCESSOR_KEY not in st .session_state :
5261 st .session_state [PANEL_ACCESSOR_KEY ] = _initialize_panel_from_base_path ()
5362
0 commit comments