This code generates a network as expected using plotly dash:
import dash
from dash import dcc
from dash import html
import dash_cytoscape as cyto
from dash.dependencies import Input, Output
import plotly.express as px
dash_elements = [{'data': {'id': '6840', 'label': '6840'}, 'classes': 'black'}, {'data': {'id': '7431', 'label': '7431'}, 'classes': 'red'}, {'data': {'source': '6840', 'target': '7431'}}, {'data': {'id': '6640', 'label': '6640'}, 'classes': 'black'}, {'data': {'id': '5217', 'label': '5217'}, 'classes': 'black'}, {'data': {'source': '6640', 'target': '5217'}}, {'data': {'id': '823', 'label': '823'}, 'classes': 'black'}, {'data': {'id': '7431', 'label': '7431'}, 'classes': 'red'}, {'data': {'source': '823', 'target': '7431'}}]
app = dash.Dash(__name__)
styles = {
'pre': {
'border': 'thin lightgrey solid',
'overflowX': 'scroll'
}
}
default_stylesheet=[
# Class Selectors
{
'selector':'.black',
#'selector': 'node',
'style': {
'background-color': '#000000',
'label': 'data(label)'
},
},
{
'selector':'.red',
#'selector':'node',
'style': {
'background-color': '#FF0000',
'label': 'data(label)'
},
},
]
app.layout = html.Div([
#html.P("Dash Cytoscape:"),
cyto.Cytoscape(
id='cytoscape-event-callbacks-2',
elements = dash_elements,
layout={'name': 'breadthfirst'},
#layout={'name': 'preset'},
style={'width': '1000px', 'height': '1000px'},
stylesheet = default_stylesheet
),
html.P(id='cytoscape-tapNodeData-output'),
html.P(id='cytoscape-tapEdgeData-output'),
html.P(id='cytoscape-mouseoverNodeData-output'),
html.P(id='cytoscape-mouseoverEdgeData-output')
])
@app.callback(Output('page-content', 'children'),
Input('cytoscape-event-callbacks-2', 'tapNodeData'))
#app.callback(Output('url', 'children'),
# Input('cytoscape-event-callbacks-2', 'tapNodeData'))
def displayTapNodeData(data):
if data:
return "https://www.ncbi.nlm.nih.gov/gene/" + str(data['label'])
@app.callback(Output('cytoscape-tapEdgeData-output', 'children'),
Input('cytoscape-event-callbacks-2', 'tapEdgeData'))
def displayTapEdgeData(data):
if data:
return "There is a physical interaction between " + \
str(data['source']) + " and " + str(data['target'])
@app.callback(Output('cytoscape-mouseoverNodeData-output', 'children'),
Input('cytoscape-event-callbacks-2', 'mouseoverNodeData'))
def displayTapNodeData(data):
if data:
return "https://www.ncbi.nlm.nih.gov/gene/" + str(data['label'])
@app.callback(Output('cytoscape-mouseoverEdgeData-output', 'children'),
Input('cytoscape-event-callbacks-2', 'mouseoverEdgeData'))
def displayTapEdgeData(data):
if data:
return "There is a physical interaction between " + \
str(data['source']) + " and " + str(data['target'])
if __name__ == '__main__':
app.run_server()
The output:
When I click on a node, as expected, text in the bottom left appears with the URL to find out more information about the node.
I just want to turn that text into a hyperlink.
I can see the example documentation to do that here and I can get this sample code to work.
I am unclear specifically which changes I make to my own code to incorporate this, I've left the attempt I've tried commented out, where I thought I would input a tapNodeData and the output would be a url.
If someone could demonstrate how to convert what is returned upon click to a URL I'd appreciate it.


