Skip to content

Commit 629facc

Browse files
authored
Add Streamlit Custom Component to Refresh Panel (#68)
* adding refresh component Signed-off-by: Valerie Gleason πŸ‘Œ <[email protected]> * moving refresh component to separate namespace Signed-off-by: Valerie Gleason πŸ‘Œ <[email protected]> * fixing formatting Signed-off-by: Valerie Gleason πŸ‘Œ <[email protected]> * rename refresh method Signed-off-by: Valerie Gleason πŸ‘Œ <[email protected]> * fixing import Signed-off-by: Valerie Gleason πŸ‘Œ <[email protected]> * fixing imports Signed-off-by: Valerie Gleason πŸ‘Œ <[email protected]> * fixing package structure and import error Signed-off-by: Valerie Gleason πŸ‘Œ <[email protected]> * fix stale comment * changing panel to panel-service Signed-off-by: Valerie Gleason πŸ‘Œ <[email protected]> --------- Signed-off-by: Valerie Gleason πŸ‘Œ <[email protected]>
1 parent 1857f57 commit 629facc

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
STREAMLIT_PYTHON_PANEL_SERVICE = "ni.pythonpanel.v1.PythonPanelService"
2+
STREAMLIT_REFRESH_COMPONENT_URL = "http://localhost:42001/panel-service/refresh"

β€Žsrc/nipanel/_streamlit_panel_initializer.pyβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import streamlit as st
44

55
from nipanel._streamlit_panel_value_accessor import StreamlitPanelValueAccessor
6+
from nipanel.streamlit_refresh import initialize_refresh_component
67

78
PANEL_ACCESSOR_KEY = "StreamlitPanelValueAccessor"
89

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

2425
panel = cast(StreamlitPanelValueAccessor, st.session_state[PANEL_ACCESSOR_KEY])
25-
# TODO: declare the refresh component here
26+
refresh_component = initialize_refresh_component(panel.panel_id)
27+
refresh_component()
2628
return panel
2729

2830

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Initializes a refresh component for Streamlit."""
2+
3+
from typing import Any
4+
5+
import streamlit.components.v1 as components
6+
7+
from nipanel._streamlit_constants import STREAMLIT_REFRESH_COMPONENT_URL
8+
9+
10+
def initialize_refresh_component(panel_id: str) -> Any:
11+
"""Initialize a refresh component to the Streamlit app."""
12+
_refresh_component_func = components.declare_component(
13+
"panelRefreshComponent",
14+
url=f"{STREAMLIT_REFRESH_COMPONENT_URL}/{panel_id}",
15+
)
16+
17+
return _refresh_component_func

0 commit comments

Comments
Β (0)