IR-kernel / Tornado Crash Caused by rglwidget when sourcing R file but not if executed in cell

Hi Everyone,
Having a strange issue. If I use the following 4 lines of R code in a cell the kernel disconnects on the fourth line:

source("setup.R", local=FALSE)
view3d(theta=-20, phi=-3, fov=30, zoom=0.85)
rglwidget(width=640, height=480)

If I add the contents of setup.R in the cell everything works.

The logs show:

[D 2023-06-07 17:25:43.288 SingleUserNotebookApp zmqhandlers:159] Opening websocket /user/guest21/terminals/websocket/1
Task exception was never retrieved
future: <Task finished name='Task-15196' coro=<WebSocketProtocol13.write_message.<locals>.wrapper() done, defined at /opt/conda/lib/python3.11/site-packages/tornado/> exception=WebSocketClosedError()>
Traceback (most recent call last):
  File "/opt/conda/lib/python3.11/site-packages/tornado/", line 1087, in wrapper
    await fut
tornado.iostream.StreamClosedError: Stream is closed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/opt/conda/lib/python3.11/asyncio/", line 267, in __step
    result = coro.send(None)
  File "/opt/conda/lib/python3.11/site-packages/tornado/", line 1089, in wrapper
    raise WebSocketClosedError()

I tried downgrading R 4.2.3 to 4.2.2, I also tried various versions of the graphics libraries and notebook versions.

I checked the file for special characters, etc…The setup.R file is large, so I put it on Google drive:

I tested many things I found on the web with no luck.

Any ideas on what to try ?

Thanks for looking :slight_smile: