If possible I would like to send command line requests to the running slicer instance, similar to Slicer.exe --python-code "slicer.util.loadScene('f:/2013-08-23-Scene.mrb')" or Slicer.exe --python-code "doSomething; doSomethingElse; etc." --testing --no-splash --no-main-window
Ultimately I am trying to figure out a way to create a way to open a slicer window from a custom web application, by creating a button which would execute a command, which opens a locally stored nifti file with the running slicer instance (and visible in the vnc window). I know that this exists - New DICOMweb features: launch Slicer from web browser and download/upload data sets to the cloud using DICOMweb but in my case, all the files can be stored in the local storage, no communication with external DICOMWeb databases is necessary.
Is it possible with SlicerDockers? Or is there a better way to achieve similar functionality?
Yes, you can send commands to a running Slicer with the WebServer module and the slicer/exec endpoint. You can use the --python-code command line option to make sure the WebServer is running at startup. The exec endpoint allows you to execute arbitrary python code and get the results via http (of course be careful who has access to this endpoint!). You would also need to expose the port from your docker run command, 2016 by default. If you have shared the volume with the files to the docker instance then you can load the files using the passed in commands and have them show up in your vnc window.
Thank you for your answer!
I not yet sure how can I launch the WebServer using GitHub - pieper/SlicerDockers: docker config files for slicer .
WebServer module does not seem to be available in the Slicer instance hosted in the vnc. Is there a way to enable it either after start or when starting the docker container/inside the docker container?
I managed to add the WebServer module using GitHub - pieper/SlicerWeb: Slicer modules that support web services and web applications and adding the --env SLICER_ARGUMENTS="--additional-module-paths /home/researcher/Documents/SlicerWeb/WebServer" argument to the docker run command. However this way does seem to be limited in functionality, as I can only open the http://localhost:2016/ (by exposing the port) but exec commands does not seem to be available (returns unknown command "/exec") probably because I do not see the option to start server in the Web Server module started in this way.
Slicer-5.0.3 has the Web Server module built in, so there is no need to set up anything else. You can start Slicer (with the exec interface enabled) from the command line like this:
Right, but for my usecase, I need the Slicer to be running in a docker container and accessible via vnc client, so I am using GitHub - pieper/SlicerDockers: docker config files for slicer . However, SlicerDockers seems to run the Slicer version 5.0.2 version, so thats probably why the Web Server module in not available in the launched Slicer instance. Maybe I can try to manually rebuild the docker with Slicer version 5.0.3 or are there are better alternatives?
@NaglisR did you run stevepieper/slicer:5.0.2 ? that should have the WebServer option built in. I haven’t had a chance to update to 5.0.3 yet but 5.0.2 should work the same mostly. Let us know how it goes.
Step 7/7 : RUN for ext in ${SLICER_EXTS} ; do echo "Installing ${ext}" ; EXTENSION_TO_INSTALL=${ext} su researcher -c "xvfb-run --auto-servernum /opt/slicer/Slicer --python-script /tmp/install-slicer-extension.py" ; done
---> Running in 975b22429285
Installing MarkupsToModel
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-researcher'
Switch to module: "Welcome"
installing MarkupsToModel
Traceback (most recent call last):
File "<string>", line 5, in <module>
File "<string>", line 7, in <module>
AttributeError: qSlicerExtensionsManagerModel has no attribute named 'retrieveExtensionMetadataByName'
Thanks testing this - I was mistaken, the 5.0.2 version didn’t have the WebServer module as you discovered. I’m looking into updating the images to include a 5.0.3 version. I’ll report back if I get one uploaded. We should be able to fix the extensions (slicer-plus image) but the base slicer image wouldn’t need the extension manager so you can probably run that even if the build script doesn’t complete.
If you want to experiment without fixing the docker, you can also just copy the WebServer code directly from the Slicer source code into the module path of the 5.0.2 instance. There’s no compilation needed and I don’t think there’s even any configuration done during the cmake process, just copying the files.
Great! Your use case with a custom web app and containerized Slicer access sounds pretty interesting. If you can share your app source code, or just a small demo script, that would be good for others to learn from.