File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed
src/nipanel/streamlit_refresh Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change 11"""Initializes a refresh component for Streamlit."""
22
3+ from typing import ClassVar
4+
5+ from ni_measurement_plugin_sdk_service .discovery import DiscoveryClient
6+ from ni_measurement_plugin_sdk_service .grpc .channelpool import GrpcChannelPool
37from streamlit .components .v1 import declare_component
48from streamlit .components .v1 .custom_component import CustomComponent
59
610
11+ class _ServiceResolver :
12+
13+ _panel_service_proxy_location : ClassVar [str | None ] = None
14+
15+ @classmethod
16+ def get_or_resolve_proxy (cls ) -> str :
17+ if cls ._panel_service_proxy_location is None :
18+ discovery_client = DiscoveryClient (grpc_channel_pool = GrpcChannelPool ())
19+ service_location = discovery_client .resolve_service (
20+ provided_interface = "ni.http1.proxy" ,
21+ service_class = "" ,
22+ )
23+ cls ._panel_service_proxy_location = service_location .insecure_address
24+
25+ return cls ._panel_service_proxy_location
26+
27+
728def initialize_refresh_component (panel_id : str ) -> CustomComponent :
829 """Initialize a refresh component to the Streamlit app."""
9- proxy_url = "TODO"
30+ proxy_base_address = _ServiceResolver .get_or_resolve_proxy ()
31+ component_url = f"http://{ proxy_base_address } /panel-service/refresh/{ panel_id } "
1032 _refresh_component_func = declare_component (
1133 "panelRefreshComponent" ,
12- url = f"http:// { proxy_url } /panel-service/refresh/ { panel_id } " ,
34+ url = component_url ,
1335 )
1436
1537 return _refresh_component_func
You can’t perform that action at this time.
0 commit comments