diff --git a/examples/sample/README.md b/examples/sample/README.md new file mode 100644 index 0000000..38e3292 --- /dev/null +++ b/examples/sample/README.md @@ -0,0 +1,15 @@ +## Sample + +This is a nipanel example that displays an interactive Streamlit app and updates its values. + +### Feature + +- Supports various data types + +### Required Software + +- Python 3.9 or later + +### Usage + +Run `poetry run examples/sample/sample.py` \ No newline at end of file diff --git a/examples/sample/sample.py b/examples/sample/sample.py new file mode 100644 index 0000000..a6d867f --- /dev/null +++ b/examples/sample/sample.py @@ -0,0 +1,22 @@ +"""This example demonstrates how to open/update a Streamlit application using nipanel package.""" + +import pathlib + +import nipanel + +script_path = pathlib.Path(__file__) +panel_script_path = str(script_path.with_name("sample_panel.py")) + +panel = nipanel.StreamlitPanel( + panel_id="sample_panel", + streamlit_script_uri=panel_script_path, +) +panel.open_panel() +panel.set_value("sample_string", "Hello, World!") +panel.set_value("sample_int", 42) +panel.set_value("sample_float", 3.14) +panel.set_value("sample_bool", True) + +input("Press Enter to close the panel...") + +panel.close_panel(reset=True) diff --git a/examples/sample/sample_panel.py b/examples/sample/sample_panel.py new file mode 100644 index 0000000..e1a6c93 --- /dev/null +++ b/examples/sample/sample_panel.py @@ -0,0 +1,23 @@ +"""Streamlit application script for displaying values using nipanel package.""" + +import streamlit as st + +import nipanel + +panel = nipanel.StreamlitPanelValueAccessor(panel_id="sample_panel") + +st.title("Sample Panel") + +col1, col2 = st.columns([0.4, 0.6]) + +with col1: + st.write("String") + st.write("Integer") + st.write("Float") + st.write("Boolean") + +with col2: + st.write(panel.get_value("sample_string")) + st.write(panel.get_value("sample_int")) + st.write(panel.get_value("sample_float")) + st.write(panel.get_value("sample_bool"))