Skip to content

Commit 1a1bcd0

Browse files
committed
Add server_host param
1 parent 09eb63f commit 1a1bcd0

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/vitessce/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,7 @@ def widget(self, **kwargs):
18151815
:param bool page_mode: Whether to render the <Vitessce/> component in grid-mode or page-mode. By default, False.
18161816
:param str page_esm: The ES module string for the page component creation function. Optional.
18171817
:param bool prevent_scroll: Should mouseover in the Vitessce widget prevent disable the scrolling of the notebook? By default, True.
1818+
:param str server_host: The host to which the Uvicorn server should bind. Specify "0.0.0.0" to bind to all interfaces. By default, "127.0.0.1".
18181819
18191820
:returns: The Jupyter widget.
18201821
:rtype: VitessceWidget

src/vitessce/widget.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def stop(self):
4040
self.thread = None
4141
return self
4242

43-
def start(self, port=None, timeout=1, daemon=True, log_level="warning"):
43+
def start(self, port=None, host=None, timeout=1, daemon=True, log_level="warning"):
4444
from uvicorn import Config, Server
4545
from threading import Thread
4646

@@ -50,6 +50,7 @@ def start(self, port=None, timeout=1, daemon=True, log_level="warning"):
5050
config = Config(
5151
app=self.app,
5252
port=port,
53+
host=(host if host is not None else "127.0.0.1"),
5354
timeout_keep_alive=timeout,
5455
log_level=log_level
5556
)
@@ -117,15 +118,15 @@ def get_base_url_and_port(port, next_port, proxy=False, base_url=None, host_name
117118
return base_url, use_port, next_port
118119

119120

120-
def serve_routes(config, routes, use_port):
121+
def serve_routes(config, routes, use_port, server_host):
121122
if not config.has_server(use_port) and len(routes) > 0:
122123
server = BackgroundServer(routes)
123124
config.register_server(use_port, server)
124125
data_server.register(config)
125-
server.start(port=use_port)
126+
server.start(port=use_port, host=server_host)
126127

127128

128-
def launch_vitessce_io(config, theme='light', port=None, base_url=None, host_name=None, proxy=False, open=True):
129+
def launch_vitessce_io(config, theme='light', port=None, base_url=None, host_name=None, proxy=False, open=True, server_host=None):
129130
import webbrowser
130131
base_url, use_port, _ = get_base_url_and_port(
131132
port, DEFAULT_PORT, proxy=proxy, base_url=base_url, host_name=host_name)
@@ -136,7 +137,7 @@ def launch_vitessce_io(config, theme='light', port=None, base_url=None, host_nam
136137
if len(stores) > 0:
137138
raise ValueError('One or more files in this configuration have been provided via Zarr store, which can only be loaded via the widget. Either use VitessceConfig.widget or VitessceConfig.display (instead of .web_app), or provide the files via _path or _url (rather than _store) parameters.')
138139

139-
serve_routes(config, routes, use_port)
140+
serve_routes(config, routes, use_port, server_host)
140141
vitessce_url = f"http://vitessce.io/#?theme={theme}&url=data:," + quote_plus(
141142
json.dumps(config_dict))
142143
if open:
@@ -663,7 +664,7 @@ class VitessceWidget(anywidget.AnyWidget):
663664

664665
store_urls = List(trait=Unicode(''), default_value=[]).tag(sync=True)
665666

666-
def __init__(self, config, height=600, theme='auto', uid=None, port=None, proxy=False, js_package_version='3.6.18', js_dev_mode=False, custom_js_url='', plugins=None, remount_on_uid_change=True, prefer_local=True, invoke_timeout=300000, invoke_batched=True, page_mode=False, page_esm=None, prevent_scroll=True):
667+
def __init__(self, config, height=600, theme='auto', uid=None, port=None, proxy=False, js_package_version='3.6.18', js_dev_mode=False, custom_js_url='', plugins=None, remount_on_uid_change=True, prefer_local=True, invoke_timeout=300000, invoke_batched=True, page_mode=False, page_esm=None, prevent_scroll=True, server_host=None):
667668
"""
668669
Construct a new Vitessce widget. Not intended to be instantiated directly; instead, use ``VitessceConfig.widget``.
669670
@@ -684,6 +685,7 @@ def __init__(self, config, height=600, theme='auto', uid=None, port=None, proxy=
684685
:param bool page_mode: Whether to render the <Vitessce/> component in grid-mode or page-mode. By default, False.
685686
:param str page_esm: The ES module string for the page component creation function. Optional.
686687
:param bool prevent_scroll: Should mouseover in the Vitessce widget prevent disable the scrolling of the notebook? By default, True.
688+
:param str server_host: The host to which the Uvicorn server should bind. Specify "0.0.0.0" to bind to all interfaces. By default, "127.0.0.1".
687689
688690
Note: these parameter docstrings need to be manually kept in sync with the VitessceConfig.widget docstring.
689691
"""
@@ -732,7 +734,7 @@ def handle_config_change(change):
732734

733735
self.observe(handle_config_change, names=['_config'])
734736

735-
serve_routes(config, routes, use_port)
737+
serve_routes(config, routes, use_port, server_host)
736738

737739
def _get_coordination_value(self, coordination_type, coordination_scope):
738740
obj = self._config['coordinationSpace'][coordination_type]
@@ -796,15 +798,15 @@ def _plugin_command(self, params, buffers):
796798
# Launch Vitessce using plain HTML representation (no ipywidgets)
797799

798800

799-
def ipython_display(config, height=600, theme='auto', base_url=None, host_name=None, uid=None, port=None, proxy=False, js_package_version='3.6.18', js_dev_mode=False, custom_js_url='', plugins=None, remount_on_uid_change=True, page_mode=False, page_esm=None):
801+
def ipython_display(config, height=600, theme='auto', base_url=None, host_name=None, uid=None, port=None, proxy=False, js_package_version='3.6.18', js_dev_mode=False, custom_js_url='', plugins=None, remount_on_uid_change=True, page_mode=False, page_esm=None, server_host=None):
800802
from IPython.display import display, HTML
801803
uid_str = "vitessce" + get_uid_str(uid)
802804

803805
base_url, use_port, _ = get_base_url_and_port(
804806
port, DEFAULT_PORT, proxy=proxy, base_url=base_url, host_name=host_name)
805807
config_dict = config.to_dict(base_url=base_url)
806808
routes = config.get_routes()
807-
serve_routes(config, routes, use_port)
809+
serve_routes(config, routes, use_port, server_host)
808810

809811
plugins = plugins or []
810812
plugin_esm = [p.plugin_esm for p in plugins]

0 commit comments

Comments
 (0)