I want to connect a Bokeh Application with Electron. The Electron window already shows the localhost:5006 of the bokeh application written in Python 3. Now I want to use the native user menu of electron to fire some actions of the Bokeh application. Is there any way to do this?
- 9,352
 - 5
 - 51
 - 114
 
1 Answers
I have used some workarounds to achieve that in this project. Concretely I send signals to the iframe to run some js event and trigger python methods. In the future I hope bokeh will permit some RPC calls. The key files to get the functionality:
- I load bokeh on an iframe in order to control the whole app from electron.
 I send the signal to the iframe with this method.
document.getElementById('bokeh_iframe').contentWindow.postMessage({ "signal": "call-python-promise", "message_data": message } , '*'); // to index.html, the click on the button is run there as wellOne call example here. You can place those calls in the electron menu items (in the ipc renderer side).
var call_params = { 'object': 'bokeh.loader', 'method': 'init_bokeh', 'args': { 'ts_state': $('body').data('ts_state'), } } tools.call_promise(call_params).then((result) => { self.run_on_ready(); });This object creates the machinery to trigger callbacks from js. A small bokeh form constructed with a button, a input text and a plot.
- Here I fill the dummy text object to select the method to call (object and method). Then I trigger the python method (callback associated to the button) with 
button.click() - The object and method are received and computed in the python side. Finally, the bokeh method returns the answer to electron with the reversed process as I have exposed here.
 
As you can see this is quite cumbersome. If you find a better way to do it let me know. Some way to call python methods will be created in the future and all of this will be simpler.
Note: You may need to check when bokeh is loaded to redirect electron. Check this question and answer
- 9,352
 - 5
 - 51
 - 114