Skip to content

Commit 259f2e4

Browse files
committed
BUG: Fix functionality in Colab
When running a notebook in Colab the viewer was failing on to_ngff_zarr. It seems that in Colab specifically there are issues using Dask from an asynchronous function. By moving this to the (now) synchronous setup function we avoid this issue.
1 parent f26e8ba commit 259f2e4

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

itkwidgets/viewer.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,23 @@ def _get_input_data(self):
4747
inputs.append((option, data))
4848
return inputs
4949

50-
async def setup(self):
51-
pass
50+
def setup(self):
51+
self.init_data.clear()
52+
input_data = self._get_input_data()
53+
result= None
54+
for (input_type, data) in input_data:
55+
render_type = _detect_render_type(data, input_type)
56+
key = init_key_aliases()[input_type]
57+
if render_type is RenderType.IMAGE:
58+
if input_type == 'label_image':
59+
result = _get_viewer_image(data, label=True)
60+
else:
61+
result = _get_viewer_image(data, label=False)
62+
elif render_type is RenderType.POINT_SET:
63+
result = _get_viewer_point_sets(data)
64+
if result is None:
65+
result = data
66+
self.init_data[key] = result
5267

5368
async def run(self, ctx):
5469
"""ImJoy plugin setup function."""
@@ -73,24 +88,6 @@ async def run(self, ctx):
7388
else:
7489
config = {}
7590

76-
inputs = self._get_input_data()
77-
78-
self.init_data.clear()
79-
result= None
80-
for (input_type, data) in inputs:
81-
render_type = _detect_render_type(data, input_type)
82-
key = init_key_aliases()[input_type]
83-
if render_type is RenderType.IMAGE:
84-
if input_type == 'label_image':
85-
result = _get_viewer_image(data, label=True)
86-
else:
87-
result = _get_viewer_image(data, label=False)
88-
elif render_type is RenderType.POINT_SET:
89-
result = _get_viewer_point_sets(data)
90-
if result is None:
91-
result = data
92-
self.init_data[key] = result
93-
9491
itk_viewer = await api.createWindow(
9592
name=f"itkwidgets viewer {_viewer_count}",
9693
type="itk-vtk-viewer",

0 commit comments

Comments
 (0)