# Reload data via UI

**URL:** <https://discourse.slicer.org/t/reload-data-via-ui/26204>\
**Category:** Support\
**Created:** [November 11, 2022, 8:14pm UTC](https://discourse.slicer.org/t/reload-data-via-ui/26204 "2022-11-11T20:14:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karl\_Hahn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/karl_hahn/32/15290_2.png) [@Karl\_Hahn](https://discourse.slicer.org/u/Karl_Hahn)\
**Post date:** [November 11, 2022, 8:14pm UTC](https://discourse.slicer.org/t/reload-data-via-ui/26204/1 "2022-11-11T20:14:11Z")

</div>

Hello,

Is there already a way to reload data from disk?

Example use case would be to load a scene in slicer containing (say) a model, run some external tool that modifies that mesh, and reload and inspect the result in slicer.

---

<div class="post-metadata">

**Author:** ![gcsharp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gcsharp/32/863_2.png) [@gcsharp](https://discourse.slicer.org/u/gcsharp)\
**Post date:** [November 11, 2022, 8:22pm UTC](https://discourse.slicer.org/t/reload-data-via-ui/26204/2 "2022-11-11T20:22:50Z")

</div>

Not that I know of. I think you’d need to use python.

Personally I think this would be super useful. For example a “reload” context menu item on the Data module.

---

<div class="post-metadata">

**Author:** ![Karl\_Hahn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/karl_hahn/32/15290_2.png) [@Karl\_Hahn](https://discourse.slicer.org/u/Karl_Hahn)\
**Post date:** [November 11, 2022, 8:24pm UTC](https://discourse.slicer.org/t/reload-data-via-ui/26204/3 "2022-11-11T20:24:39Z")

</div>

> For example a “reload” context menu item on the Data module.

Exactly. Agreed that it would be invaluable to have this functionality out of the box.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 11, 2022, 8:42pm UTC](https://discourse.slicer.org/t/reload-data-via-ui/26204/4 "2022-11-11T20:42:16Z")

</div>

Using CLI module infrastructure for launching external tools is much more versatile and user-friendly (you may just need to write a wrapper Python script that launches the tool - see example [here](https://github.com/lassoan/SlicerPythonCLIExample/blob/master/BlurImage/BlurImage.py)).

You can also make Slicer to update/load data using the Web Server API from any Python script [using the slicerio Python package](https://slicer.readthedocs.io/en/latest/user_guide/modules/webserver.html#usage-via-slicerio-python-package). For example, you can run this Python command in your external tool to load the result image into Slicer:

```python
# Prerequisite: pip install slicerio
import slicerio.server
slicerio.server.file_load("c:/tmp/MRHead.nrrd")

```

Then you don’t need to switch to Slicer, find the data node in the tree that you want to update, right-click on it, and choose Refresh, but it would be all automatic.

We could add a command for updating a node from a file, something like `slicerio.server.file_load("c:/tmp/MRHead.nrrd", "MyVolumeNode")` could update the node named “MyVlumeNode” with the content of the provided file.

---

<div class="post-metadata">

**Author:** ![Karl\_Hahn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/karl_hahn/32/15290_2.png) [@Karl\_Hahn](https://discourse.slicer.org/u/Karl_Hahn)\
**Post date:** [November 11, 2022, 9:46pm UTC](https://discourse.slicer.org/t/reload-data-via-ui/26204/5 "2022-11-11T21:46:40Z")

</div>

@lassoan Thanks for the example. `slicerio` seems like it could indeed facilitate the use case described. Unfortunately, I’m unable to get it working.

Running below gives following results:

```auto
slicerio.server.file_load(r"...\mesh.ply", slicer_executable=r"...\path\to\Slicer.exe")

```

- 5.0.3: application starts, but nothing loaded; eventually receive `requests.exceptions.ConnectTimeout: Timeout while waiting for application to start`
- 5.1.0 nightly: `AttributeError: 'WebServerLogic' object has no attribute 'enableCORS'`

> We could add a command for updating a node from a file

I think that would be helpful, indeed.

Edit:  
Just saw in `slicerio.server.start_server` that version 5.2 is required…

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [November 11, 2022, 9:54pm UTC](https://discourse.slicer.org/t/reload-data-via-ui/26204/6 "2022-11-11T21:54:58Z")

</div>

@Karl_Hahn Are you able to start the web server manually with the GUI for either version? The server is working for me with both 5.0.3 and my local build of the main github branch.

---

<div class="post-metadata">

**Author:** ![Karl\_Hahn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/karl_hahn/32/15290_2.png) [@Karl\_Hahn](https://discourse.slicer.org/u/Karl_Hahn)\
**Post date:** [November 11, 2022, 10:08pm UTC](https://discourse.slicer.org/t/reload-data-via-ui/26204/7 "2022-11-11T22:08:48Z")

</div>

Hi @pieper, I seem to be able to do so.

In 5.0.3, via the `Web Server` module, choosing “Start server”:

```auto
Server stopped.
Starting server on port 2016
docroot: b'C:/ProgramData/NA-MIC/Slicer 5.0.3/bin/../lib/Slicer-5.0/qt-scripted-modules/Resources/docroot'
started httpserver...
listening on 3928...

```

After doing this, I then naively attempted to run the following in an external script:

```auto
slicerio.server.file_load(
    file_path=r"...\path\to\mesh.ply",
    file_type='ModelFile',
    properties=dict(name='mesh')
)

```

Nothing seems to load in the UI. I do, however, see that the HTTP server received a request and processed it without reporting an error.

Is this a valid use case?

Edit:  
Running instead:

```auto
>>> slicerio.server.is_server_running()
False

```

---

<div class="post-metadata">

**Author:** ![Karl\_Hahn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/karl_hahn/32/15290_2.png) [@Karl\_Hahn](https://discourse.slicer.org/u/Karl_Hahn)\
**Post date:** [November 11, 2022, 10:20pm UTC](https://discourse.slicer.org/t/reload-data-via-ui/26204/8 "2022-11-11T22:20:14Z")

</div>

Happily, repeating the above in a 5.1.0 nightly produces the expected result.

In this case, manually starting the web server prompted for a windows firewall exception to be created. This same thing did not happen for 5.0.3.

Edit:  
After manually removing all firewall entries for slicer, I restarted 5.0.3 and received the prompt for firewall exception. Unfortunately, `slicerio.server.file_load` still has no effect despite the server apparently processing the request.

---

<div class="post-metadata">

**Author:** ![Karl\_Hahn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/karl_hahn/32/15290_2.png) [@Karl\_Hahn](https://discourse.slicer.org/u/Karl_Hahn)\
**Post date:** [November 11, 2022, 10:55pm UTC](https://discourse.slicer.org/t/reload-data-via-ui/26204/9 "2022-11-11T22:55:20Z")

</div>

@lassoan Ran into an issue, but perhaps it’s better discussed in a GitHub [issue](https://github.com/lassoan/slicerio/issues/3). Thanks for your help!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 11, 2022, 11:07pm UTC](https://discourse.slicer.org/t/reload-data-via-ui/26204/10 "2022-11-11T23:07:16Z")

</div>

This all requires recent Slicer Preview Release (or the new stable release 5.2 that will be out in a few days). I don’t think Slicer 5.0.3 supports the necessary commands.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 12, 2022, 3:36am UTC](https://discourse.slicer.org/t/reload-data-via-ui/26204/11 "2022-11-12T03:36:22Z")

</div>

I’ve fixed the CORS error message and the node deletion issue that was reported in GitHub.

I’ve also added a function to slicerio (0.1.8) to reload an already loaded node (in case the file is changed on disk):

```python
nodeID = slicerio.server.file_load("path/to/Segmentation.seg.nrrd", "SegmentationFile")
# ... some changes are made in the file, make Slicer reload the node from the modified file
slicerio.server.node_reload(id=nodeID)

```

---

<div class="post-metadata">

**Author:** ![Karl\_Hahn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/karl_hahn/32/15290_2.png) [@Karl\_Hahn](https://discourse.slicer.org/u/Karl_Hahn)\
**Post date:** [November 12, 2022, 7:44am UTC](https://discourse.slicer.org/t/reload-data-via-ui/26204/12 "2022-11-12T07:44:07Z")

</div>

Awesome, looking forward to checking it out. Thanks for your help!
