2

I have a dataframe like this:

category source_node  target_node
cat1  node1  target1
cat1  node2  target1
cat1  node2  target2
cat1  node2  target3
cat1  node2  target4
cat2  node3  target1
cat2  node3  target1
cat2  node4  target7
cat2  node6  target7

I want to use dash (or a similar, interactive library) to first draw a bubble plot where each category is a separate bubble (ideally with a size linked to the number of items in the category but I can figure that out after), and then when you click on a bubble, a network is produced based on the source and target nodes in that bubble/category.

This is a dictionary of each category, and the source and target nodes in each category:

#A dict of source nodes (called nodes) and target nodes (called targets) that will be linked via edges in a$
node_list_dict = {'cat1':['node1','node2','target1','target2','target3','target4'],
             'cat2':['node3','node4','node6','target1','target7']}

This is a dictionary of each category, and the location of each bubble in the bubble plot:

#A dict of categories and the location of the categories in the bubble plot
node_plot_location_dict = {'cat1':[10,4],'cat2':[3,4]}

This is the code to draw the bubble plot:

#How to draw the bubble plot
fig = go.Figure(data=[go.Scatter(
    x = [node_plot_location_dict[i][0] for i in node_plot_location_dict],
    y = [node_plot_location_dict[i][1] for i in node_plot_location_dict],
    mode='markers',
    marker_size=[40, 60, 80])
])

fig.show()

And this is the code to draw a network:

#How to draw the network
import plotly.graph_objects as go
import networkx as nx
import matplotlib.pyplot as plt

dict1 = {'cat1':[{'start':'node1','end':'target1'},
                {'start':'node2','end':'target1'},
                {'start':'node2','end':'target2'},
                {'start':'node2','end':'target3'},
                {'start':'node2','end':'target4'}]}

G = nx.Graph()
for pts in dict1['cat1']:
    G.add_edge(pts['start'], pts['end'])
nx.draw(G)
plt.show()

Then, once I'm in the network, I want to click on a node in the network which will be a hyperlink to a page. Someone kindly suggested code that could be used for that purpose here.

I'm struggling to link the bubble plot to a network, so that when i 'press' a bubble in the bubble plot, a network is generated.

Could someone show me how to piece this code together so that I can use dash to make an interactive bubble plot where clicking on a bubble leads a network based on the items in that bubble?

Just to mention that I chose these libraries because they're the ones I could figure out a solution in, but I'm open to changing the library used as long as it's in python and can work in jupyter or an interface like dash.

Slowat_Kela
  • 1,377
  • 2
  • 22
  • 60
  • Based on your stated requirements, I'm guessing your users are not going to be very adept at interacting with the data outside of the click interactions you hope to provide in these plots. I'd suggest implementing the whole thing end-to-end in either bokeh OR plotly after carefully studying the network plotting tutorials for each and researching your 'link-out on click' requirement. I think the scope of the question is just too large and there are too many technical/design/usability unknowns here for must users to be able to devote the time to a solution. – Frodnar Oct 16 '21 at 10:00
  • If both visualizations use the same library, then you can use some sort of cross-filtering or similar interaction between the two plots to have the bubble plot control the network plot and just have them generated side-by-side. – Frodnar Oct 16 '21 at 10:06
  • 2
    Maybe posting a bounty for this would incentivize someone to, as Frodnar points out, put in the rather larger amount of effort it would require to provide a solution to answer this for you... ‍♂️ I'd be interested in taking a stab at it but of course don't want to guarantee your bounty would be properly awarded; but I'd bet on it – John Collins Nov 01 '21 at 21:49

0 Answers0