mrjoh3 / cytoscape

An R HTMLWidget wrapper for Cytoscape.js
GNU General Public License v3.0
6 stars 2 forks source link

Add option to create graph from file [Feature Request] #3

Closed kyleweise closed 6 years ago

kyleweise commented 6 years ago

I am extremely new to JavaScript or I would try to implement this myself. I am curious as to if there is a way to extend the cytospace() function (or create a new one) to accept a properly formatted JSON file to create the graph (see here for format)

Something like cytoscapeFromFile(file = "/path/to/example.JSON"),

or possibly to separate the elements, style, and layout:

cytoscapeFromFile(elements = "elements.JSON", style = "style.JSON", layout = "layout.JSON")

Let me know your thoughts, or if you have any advice on how I would begin to code the JavaScript for such functionality.

Thanks,

-Kyle

mrjoh3 commented 6 years ago

Hi Kyle,

I suspect this would be straightforward enough as cytoscape already has a function to import/export json. Have a look at http://js.cytoscape.org/#cy.json

From r you would pass the json object. Then on the js side you would instantiate an empty cytoscape object, then use cy.json

See how you go, I will try as well over the next couple of days.

An alternative; if you already have the entire chart in a json object it may be easier to use htmltools tags to setup the chart on your page.

Matt

On Thu., 5 Jul. 2018, 19:17 kyleweise, notifications@github.com wrote:

I am extremely new to JavaScript or I would try to implement this myself. I am curious as to if there is a way to extend the cytospace() function (or create a new one) to accept a properly formatted JSON file to create the graph (see here for format http://js.cytoscape.org/#getting-started/specifying-basic-options)

Something like cytoscapeFromFile(file = "/path/to/example.JSON"),

or possibly to separate the elements, style, and layout:

cytoscapeFromFile(elements = "elements.JSON", style = "style.JSON", layout = "layout.JSON")

Let me know your thoughts, or if you have any advice on how I would begin to code the JavaScript for such functionality.

Thanks,

-Kyle

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mrjoh3/cytoscape/issues/3, or mute the thread https://github.com/notifications/unsubscribe-auth/AB1TAUeAMZQT_KrFYKMz_aYcPsjRH6btks5uDdnFgaJpZM4VDh4D .

mrjoh3 commented 6 years ago

I have had a quick go (see commit f600db844ab6d6ec7ea748a4986533bd18ad7dfb and this example). I think the implementation is correct but I can't get the json correctly formed in R. If you already have a json please test. I will have another go tomorrow.

Matt

kyleweise commented 6 years ago

I was testing with the same JSON object as you have put in README's, but had it saved as an JSON_example.JSON under data/. Still getting used to the JavaScript side of things, so I will continue at it today and possibly more this weekend and hopefully find a solution.

mrjoh3 commented 6 years ago

This finally worked. The JSON string was malformed in R. If you want to load from a file just read in the file and pass the character string as cytoscape(json = ...).

In the readme example I have left the JSON example in to illustrate to JSON format.

This issue closed with d74dded003abc2accbed4b19f4d240c49187c1c7

kyleweise commented 6 years ago

Hi Matt, looks good! One thing, looks like the png you used in the example in the README cuts off most of the graph.