Interact with the Cytoscape.js API usiing Ruby

Viewed 98

I'm writing a Ruby module for creating directed acyclic graph data structures, which will include all the functionality to add/remove nodes, edges, prevent cycles, and maintain a topological order. Eventually it will be the core of a spreadsheet-like utility to evaluate expressions that may depend on one another.

It would be really helpful, especially for testing, if my data structure could be visualized in one of the many capable js libraries for drawing graphs - I've chosen Cytoscape.js. It's pretty straightforward to set up and it has a nice javascript API to interact with and modify the graph. I would like to know if there's some way for Ruby to communicate with the browser window, and specifically with the Cytoscape instance running there. In effect, I guess I want to use the browser as a GUI for my Ruby program. Ideally, I could load my module in IRB, call my_graph.add_edge('node_a', 'node_b'), and once my Graph class checks for cycles and re-sorts as neccessary, it would call cy.add({edge JSON...}) on the Cytoscape instance and it all updates.

I'm running ruby 2.66 on Windows 10, my browser is Firefox.

Sorry if this is a naive question, I know ruby fairly well but don't know much about web development. GUIs are just not a big topic in the Ruby world and they all seem to be for making little desktop apps. I would also like to avoid the complexity of Ruby of Rails. Thanks for reading!

1 Answers

I don't know if there is a library to controll cytoscape from Ruby. Very often, Ruby libraries for science are lacking. You will have the option to create your own.

If I had to make ruby-cytoscape, I'd use https://github.com/cytoscape/cyREST.

With Ruby's method_missing and dynamic method definitions, it is not difficult to create a client that works reasonably well.

Good luck!

PS. I found this. https://github.com/kozo2/rb2cytoscape But this is just a skeleton.

Related