Codecells not trusted when running commands via the jupyter client

Hi!

I’m trying to run commands from outside jupyter using the kernel messaging protocol, which is called by a frontend UI (the project is a plugin to a markdown editor (Obsidian), and the goal is to send the code fence contents to jupyter, and display the output). I’ve gotten it to work, even with a plotly graph, and apart from some styling quirks, it works fine. I mainly followed this example in the jupyterlab repo. Where I am experiencing some problems is when the output mimetype is javascript.

When the output mimetype is javascript, like when displaying a leaflet/folium map, the output is a message saying I need to set the notebook to trusted. However, since I’m sending the commands like in the example linked above, the session is not connected to a notebook that can be accessed in the jupyter UI.

Is there a way for the kernel to recognize the session as trusted even when sending commands via the client? Or is there another preferred way to be recognized as “trusted”?

Thank you and advanced happy new year!

1 Like

I was able to do it by doing something like below, although I am sure this is a hack. Not sure if it’s the safe or preferred way to do this, but it’ll do for now!

model = new OutputAreaModel();
model.trusted = true;

1 Like