Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/sample/README.md
Original file line number Diff line number Diff line change
@@ -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`
22 changes: 22 additions & 0 deletions examples/sample/sample.py
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions examples/sample/sample_panel.py
Original file line number Diff line number Diff line change
@@ -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"))