How to load nifti file from web browser link?

The pull request to integrate the WebServer module into Slicer core is still under review:

You don’t need to wait for this to be merged. You can get the WebServer module files from that branch and copy them into your <SlicerInstallFolder>lib\Slicer-4.13\qt-scripted-modules folder then start Slicer and open the WebServer module. It starts the web server automatically. Instead of the GUI, you can also start Slicer and start the WebServer module from the command line.

After this, you can make Slicer open a file by sending a command via Slicer’s REST API. For example, you can open a file by running these few lines from any Python environment:

import requests
import sys
filename=sys.argv[-1].replace('\\','/')
port = 2016
requests.post(url=f'http://localhost:{port}/slicer/repl', data='slicer.app.loadFiles([\''+filename+'\'])', timeout=15)

You can use Slicer’s Python interpreter to run this (unlike the full Slicer application, it starts up in a second) by copying the above script into a new ShowInSlicer folder: <SlicerInstallFolder>/bin/Python/ShowInSlicer/__main__.py (this creates a Python module that can be referred to by name instead of a full path). After this, you can execute this command in the terminal:

PythonSlicer.exe -m ShowInSlicer c:\tmp\CTChest.nrrd

It will open the specified file in the running Slicer instance.

After the WebServer module will be integrated into the Slicer core, I’ll add a Python script like the one above to the Slicer core, so it will not be necessary to mess with copying files. It could also make sense to add detection of the server to the script: if the server is not running then the script could start Slicer.

1 Like