Replies: 11 comments 2 replies
-
Thank you for using justpy! I took a look and it would not be difficult to create a component to wrap cytoscape, How to do so with examples is explained here: https://justpy.io/tutorial/advanced_components/ Unfortunately, you need to know a little vue, though as you know JavaScript, if you use the examples as templates it should fine. If you get stuck, let me know and I will help you debug it. |
Beta Was this translation helpful? Give feedback.
-
I have wrapped chartjs (https://github.com/sandeep-gh/justpy-chartjs). Its functional but might have some corner cases. Take a look. I can contribute as well, if needed. |
Beta Was this translation helpful? Give feedback.
-
I finally got some time again to work on this. Have some very early code in https://github.com/aalexei/justpy-cytoscape Got something sort-of running following the signature_pad example but it seems a bit crazy. I created an event 'onJson' which I add to
Now I can listen for 'onJson' events with something like |
Beta Was this translation helpful? Give feedback.
-
Ok based on #240 (comment) and https://github.com/elimintz/justpy/blob/8952a952b533172d99a47c4062251a04c3af297c/justpy/templates/main.html async def run_method_get_output(self, method, websocket):
# adapted from https://github.com/elimintz/justpy/discussions/240
self.req_id += 1
req_id = f'cyto_{self.req_id}'
self.futures[req_id]= asyncio.get_running_loop().create_future()
await websocket.send_json(
{'type': 'run_javascript',
'data':f"Object({{value:comp_dict['{self.id}'].{method}}})",
'request_id': req_id,
'send':True}
)
result = await self.futures[req_id]
return result['value']
async def handle_page_event(self, msg):
# adapted from https://github.com/elimintz/justpy/discussions/240
if msg.event_type != 'result_ready':
return False
if not msg.request_id in self.futures:
return False
fut = self.futures[msg.request_id]
self.futures.pop(msg.request_id)
if not fut.cancelled():
fut.set_result(msg.result.copy())
return True Evaluating So now the page has to have the code |
Beta Was this translation helpful? Give feedback.
-
Any advice/criticism for https://github.com/aalexei/justpy-cytoscape most welcome. I've still to try and wrap some of the events. |
Beta Was this translation helpful? Give feedback.
-
Cytoscape events can now be bound. There are a lot of events so might leave it to the user to populate |
Beta Was this translation helpful? Give feedback.
-
Stuck on how to include Cytoscape plugins like ctxmenu. Would prefer to be able to add them via objects on the python side so the user doesn't have to go in and write js in the module. One problem is that the configuration should allow for the creation of anonymous js functions for callback actions. e.g. for ctxmenu might want to define cyto.cxtmenu({
selector: 'core',
commands: [
{ content: 'bg',
select: function(){
const edata = {
'event_type': 'ctxmenu',
'data': 'bg',
'id': props.jp_props.id,
'page_id': page_id,
'websocket_id': websocket_id
};
send_to_server(edata, 'event');
}}
]}); |
Beta Was this translation helpful? Give feedback.
-
As a functioning hack, added a plugins list of strings that get |
Beta Was this translation helpful? Give feedback.
-
Hi @aalexei , Great work including this. So far I have tried only embedding cytoscope and this work. Will take a look at events later. Two simple comments: 1) You directory structure could be |
Beta Was this translation helpful? Give feedback.
-
@elimintz what license would you prefer for components? |
Beta Was this translation helpful? Give feedback.
-
At some point updates to JustPy seem to have broken this code. The issue is related to getting results back from javascript (see 240). That is, what is the proper way to run a javascript function and get the output in justpy? |
Beta Was this translation helpful? Give feedback.
-
First of all thanks for the awesome justpy framework!
How challenging would it be to create a module wrapping Cytoscape.js (https://js.cytoscape.org)?
It can already be used to some extent with
run_javascript
calls, but it would be much more useful if there was tighter coupling between the data used by cytoscape and python data structures, so for example you could run layout routines and then save the locations to a database.There is a Vue wrapper at https://github.com/rcarcasses/vue-cytoscape but I'm not sure how up-to-date that is. I have a lot of experience with python but none with Vue.
Beta Was this translation helpful? Give feedback.
All reactions