Reload data via UI


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.

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.

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.

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).

You can also make Slicer to update/load data using the Web Server API from any Python script using the slicerio Python package. For example, you can run this Python command in your external tool to load the result image into Slicer:

# Prerequisite: pip install slicerio
import slicerio.server

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.

@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:

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.

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

@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.

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

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

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:


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?

Running instead:

>>> slicerio.server.is_server_running()

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.

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.

@lassoan Ran into an issue, but perhaps it’s better discussed in a GitHub issue. Thanks for your help!

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.

1 Like

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):

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
1 Like

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