cytoscape / jupyter-cytoscape

Cytoscape.js API support in JS, Python, and R Jupyter kernels
MIT License
10 stars 4 forks source link

Handle events on nodes/edges #5

Open rajarshi opened 7 years ago

rajarshi commented 7 years ago

Is there a mechanism to handle clicks on nodes and edges of a network displayed in a Jupyter notebook?

paul-shannon commented 7 years ago

Hi Rajarshi,

It would be easy to add. Can you describe a specific use case to guide the design?

On Apr 26, 2017, at 7:53 AM, Rajarshi Guha notifications@github.com wrote:

Is there a mechanism to handle clicks on nodes and edges of a network displayed in a Jupyter notebook?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

rajarshi commented 7 years ago

An example is at https://github.com/rajarshi/cq-notebooks/blob/master/Purple_BBTest1/BlackBoard%20Test%201.ipynb which constructs a knowledge graph via a series of calls to an external API, and then displays the graph within the notebook.

What I'd like to be able to do is handle click events on nodes/edges - for example, show the chemical structure of a drug node when clicked on. A context menu on node click would also be very handy.

Another use would be to call a function in the Jupyter notebook, when I click on a node (or make a selection on the context menu associated with a node)

pshannon commented 7 years ago

Hi Rajarshi,

I will put in some time looking at this tomorrow morning. Sorry for my delay.

On Apr 26, 2017, at 8:23 AM, Rajarshi Guha notifications@github.com wrote:

An example is at https://github.com/rajarshi/cq-notebooks/blob/master/Purple_BBTest1/BlackBoard%20Test%201.ipynb which constructs a knowledge graph via a series of calls to an external API, and then displays the graph within the notebook.

What I'd like to be able to do is handle click events on nodes/edges - for example, show the chemical structure of a drug node when clicked on. A context menu on node click would also be very handy.

Another use would be to call a function in the Jupyter notebook, when I click on a node (or make a selection on the context menu associated with a node)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

rajarshi commented 7 years ago

Not a problem. Thanks

On Thu, Apr 27, 2017 at 3:26 PM, pshannon notifications@github.com wrote:

Hi Rajarshi,

I will put in some time looking at this tomorrow morning. Sorry for my delay.

  • Paul

On Apr 26, 2017, at 8:23 AM, Rajarshi Guha notifications@github.com wrote:

An example is at https://github.com/rajarshi/cq-notebooks/blob/master/ Purple_BBTest1/BlackBoard%20Test%201.ipynb which constructs a knowledge graph via a series of calls to an external API, and then displays the graph within the notebook.

What I'd like to be able to do is handle click events on nodes/edges - for example, show the chemical structure of a drug node when clicked on. A context menu on node click would also be very handy.

Another use would be to call a function in the Jupyter notebook, when I click on a node (or make a selection on the context menu associated with a node)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cytoscape/jupyter-cytoscape/issues/5#issuecomment-297814837, or mute the thread https://github.com/notifications/unsubscribe-auth/AACGOWjEiVtaRsXY5oW1rN9VONQ74dkbks5r0OvogaJpZM4NI-3z .

-- Rajarshi Guha | http://blog.rguha.net NIH Center for Advancing Translational Science

paul-shannon commented 7 years ago

Hi again, Rajarshi.

I just tried to run your notebook, but (naturally enough) got hung up at

bb_url = 'http://localhost:9000/blackboard/api’
query = {"type":"drug", "uri":"https://pharos.ncats.io/idg/api/v1/ligands(31242)", 
     "name":"imatinib", "description": "This is an example query seeded with gleevec"}
json.dumps(query)
req = requests.post(bb_url, json=query)
req.status_code

But perhaps, from your original post, I can discern the basics of what you want to be able to do.

How about this? Over the weekend I will put in a couple of hours, enhance the cyjs widget to do at least a preliminary version (node-click popup, message back to the notebook to run a function).

Let me ask: the specific function, and the specific context menu (and the behaviors it supports) are customizations of the cytoscape widget. It is usually possible, sometime requiring signficiatn effort, to generalize (and make configurable) new features like that.

I do not think I have the time for that just now, especially with the looming need to rewrite the widget to accommodate all of the new jupyterlab/ipywidget changes.

However, even when working strictly in javascript, cytoscape.js is viewed as a programmer’s library, with each individual use requiring javascript customization. Thus, it is a different sort of beast the Cytoscape desktop.

I can give you a customized (that is, modified at the javascript level) jupyter-cyjs to show how this is done. It is likely that, to get the interactive network display that you want, that you will need to do a bit of javascript customization yourself, learning a bit about the very nice cytoscape.js api.

Is that a route you would like to go?

On Apr 27, 2017, at 1:32 PM, Rajarshi Guha notifications@github.com wrote:

Not a problem. Thanks

On Thu, Apr 27, 2017 at 3:26 PM, pshannon notifications@github.com wrote:

Hi Rajarshi,

I will put in some time looking at this tomorrow morning. Sorry for my delay.

  • Paul

On Apr 26, 2017, at 8:23 AM, Rajarshi Guha notifications@github.com wrote:

An example is at https://github.com/rajarshi/cq-notebooks/blob/master/ Purple_BBTest1/BlackBoard%20Test%201.ipynb which constructs a knowledge graph via a series of calls to an external API, and then displays the graph within the notebook.

What I'd like to be able to do is handle click events on nodes/edges - for example, show the chemical structure of a drug node when clicked on. A context menu on node click would also be very handy.

Another use would be to call a function in the Jupyter notebook, when I click on a node (or make a selection on the context menu associated with a node)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cytoscape/jupyter-cytoscape/issues/5#issuecomment-297814837, or mute the thread https://github.com/notifications/unsubscribe-auth/AACGOWjEiVtaRsXY5oW1rN9VONQ74dkbks5r0OvogaJpZM4NI-3z .

-- Rajarshi Guha | http://blog.rguha.net NIH Center for Advancing Translational Science — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

rajarshi commented 7 years ago

On Fri, Apr 28, 2017 at 12:27 PM, Paul Shannon notifications@github.com wrote:

Hi again, Rajarshi.

I just tried to run your notebook, but (naturally enough) got hung up at

bb_url = 'http://localhost:9000/blackboard/api

Actually, if you replace the above URL with https://translator.ncats.io/blackboard/api/ it should work

How about this? Over the weekend I will put in a couple of hours, enhance the cyjs widget to do at least a preliminary version (node-click popup, message back to the notebook to run a function).

Thanks - this shoudl be sufficient for our purposes

Let me ask: the specific function, and the specific context menu (and the behaviors it supports) are customizations of the cytoscape widget. It is usually possible, sometime requiring signficiatn effort, to generalize (and make configurable) new features like that.

I do not think I have the time for that just now, especially with the looming need to rewrite the widget to accommodate all of the new jupyterlab/ipywidget changes.

I completely understand.

I can give you a customized (that is, modified at the javascript level) jupyter-cyjs to show how this is done. It is likely that, to get the interactive network display that you want, that you will need to do a bit of javascript customization yourself, learning a bit about the very nice cytoscape.js api.

Is that a route you would like to go?

At one point, yes.

If it doesn't take too mich time to show an example of how I should modify the code, that is sufficient. I can't say that we will need this functionality right now - I was more interested in how such a thing could be done; so a quick example is sufficient, so as not to take up too much of your time

-- Rajarshi Guha | http://blog.rguha.net NIH Center for Advancing Translational Science

paul-shannon commented 7 years ago

Hi Rajarshi,

I just made a small change to

/jupyter-cytoscape/standalone/devel/devel.ipynb so that it will (so that it -should-) run anywhere. This notebook is my sandbox: all the cytoscape.js/python code is directly in the notebook. This makes it easy to experiment, fail quickly, add new features. Could you give it a try? If this works for you, I will be able to quickly add the few lines of code (some in javascript, some in python) for the features you requested. By the way, those features requests are completely welcome! - Paul > On Apr 28, 2017, at 10:11 AM, Rajarshi Guha wrote: > > On Fri, Apr 28, 2017 at 12:27 PM, Paul Shannon > wrote: > > > Hi again, Rajarshi. > > > > I just tried to run your notebook, but (naturally enough) got hung up at > > > > bb_url = 'http://localhost:9000/blackboard/api’ > > > > Actually, if you replace the above URL with > https://translator.ncats.io/blackboard/api/ it should work > > > > How about this? Over the weekend I will put in a couple of hours, enhance > > the cyjs widget to do at least a preliminary version (node-click popup, > > message back to the notebook to run a function). > > > > Thanks - this shoudl be sufficient for our purposes > > > > > > Let me ask: the specific function, and the specific context menu (and the > > behaviors it supports) are customizations of the cytoscape widget. It is > > usually possible, sometime requiring signficiatn effort, to generalize (and > > make configurable) new features like that. > > > > I do not think I have the time for that just now, especially with the > > looming need to rewrite the widget to accommodate all of the new > > jupyterlab/ipywidget changes. > > > > I completely understand. > > > > I can give you a customized (that is, modified at the javascript level) > > jupyter-cyjs to show how this is done. It is likely that, to get the > > interactive network display that you want, that you will need to do a bit > > of javascript customization yourself, learning a bit about the very nice > > cytoscape.js api. > > > > Is that a route you would like to go? > > > At one point, yes. > > If it doesn't take too mich time to show an example of how I should modify > the code, that is sufficient. I can't say that we will need this > functionality right now - I was more interested in how such a thing could > be done; so a quick example is sufficient, so as not to take up too much of > your time > > > > -- > Rajarshi Guha | http://blog.rguha.net > NIH Center for Advancing Translational Science > — > You are receiving this because you commented. > Reply to this email directly, view it on GitHub, or mute the thread. >