Skip to content

Commit 3a07b7d

Browse files
committed
moving refresh component to separate namespace
Signed-off-by: Valerie Gleason 👌 <valerie.gleason@emerson.com>
1 parent 6916ca9 commit 3a07b7d

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

src/nipanel/_streamlit_panel_initializer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
from streamlit.components.v1 import components
12
from typing import cast
23

34
import streamlit as st
45

56
from nipanel._streamlit_panel_value_accessor import StreamlitPanelValueAccessor
7+
from nipanel._streamlit_constants import STREAMLIT_REFRESH_COMPONENT_URL
8+
from nipanel.panel_refresh import add_refresh_component
69

710
PANEL_ACCESSOR_KEY = "StreamlitPanelValueAccessor"
811

@@ -22,7 +25,8 @@ def initialize_panel() -> StreamlitPanelValueAccessor:
2225
st.session_state[PANEL_ACCESSOR_KEY] = _initialize_panel_from_base_path()
2326

2427
panel = cast(StreamlitPanelValueAccessor, st.session_state[PANEL_ACCESSOR_KEY])
25-
# TODO: declare the refresh component here
28+
refresh_component = add_refresh_component(panel.panel_id)
29+
refresh_component()
2630
return panel
2731

2832

src/nipanel/_streamlit_panel_value_accessor.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
from __future__ import annotations
22

3-
from typing import final, Any
3+
from typing import final
44

55
import grpc
6-
import streamlit.components.v1 as components
76
from ni_measurement_plugin_sdk_service.discovery import DiscoveryClient
87
from ni_measurement_plugin_sdk_service.grpc.channelpool import GrpcChannelPool
98

109
from nipanel._panel_value_accessor import PanelValueAccessor
11-
from nipanel._streamlit_constants import (
12-
STREAMLIT_PYTHON_PANEL_SERVICE,
13-
STREAMLIT_REFRESH_COMPONENT_URL,
14-
)
10+
from nipanel._streamlit_constants import STREAMLIT_PYTHON_PANEL_SERVICE
1511

1612

1713
@final
@@ -46,12 +42,4 @@ def __init__(
4642
discovery_client=discovery_client,
4743
grpc_channel_pool=grpc_channel_pool,
4844
grpc_channel=grpc_channel,
49-
)
50-
51-
def refresh(self) -> Any:
52-
"""Get the Streamlit component for refreshing the panel."""
53-
_panel_refresh_component = components.declare_component(
54-
"panelRefreshComponent",
55-
url=f"{STREAMLIT_REFRESH_COMPONENT_URL}/{self.panel_id}",
56-
)
57-
return _panel_refresh_component()
45+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
""" Panel refresh component for Streamlit. """
2+
3+
import streamlit.components.v1 as components
4+
from nipanel._streamlit_constants import STREAMLIT_REFRESH_COMPONENT_URL
5+
6+
def add_refresh_component(panel_id):
7+
8+
refresh_component = components.declare_component(
9+
"panelRefreshComponent",
10+
url=f"{STREAMLIT_REFRESH_COMPONENT_URL}/{panel_id}",
11+
key=f"panel_refresh_{panel_id}",
12+
)
13+
14+
return refresh_component

0 commit comments

Comments
 (0)