Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions src/nipanel/_streamlit_constants.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
STREAMLIT_PYTHON_PANEL_SERVICE = "ni.pythonpanel.v1.PythonPanelService"
STREAMLIT_REFRESH_COMPONENT_URL = "http://localhost:42001/panels/refresh"
4 changes: 3 additions & 1 deletion src/nipanel/_streamlit_panel_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import streamlit as st

from nipanel._streamlit_panel_value_accessor import StreamlitPanelValueAccessor
from nipanel.panel_refresh import add_refresh_component

PANEL_ACCESSOR_KEY = "StreamlitPanelValueAccessor"

Expand All @@ -22,7 +23,8 @@ def initialize_panel() -> StreamlitPanelValueAccessor:
st.session_state[PANEL_ACCESSOR_KEY] = _initialize_panel_from_base_path()

panel = cast(StreamlitPanelValueAccessor, st.session_state[PANEL_ACCESSOR_KEY])
# TODO: declare the refresh component here
refresh_component = add_refresh_component(panel.panel_id)
refresh_component()
return panel


Expand Down
17 changes: 17 additions & 0 deletions src/nipanel/panel_refresh/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Panel refresh component for Streamlit."""

from typing import Any

import streamlit.components.v1 as components

from nipanel._streamlit_constants import STREAMLIT_REFRESH_COMPONENT_URL


def add_refresh_component(panel_id: str) -> Any:
"""Add a refresh component to the Streamlit app."""
refresh_component = components.declare_component(
"panelRefreshComponent",
url=f"{STREAMLIT_REFRESH_COMPONENT_URL}/{panel_id}",
)

return refresh_component
Loading