✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Slider not appearing on graph

Hello, I am trying to make a network graph, using networkx, that has a slider to add edges of specific orders and colors (on top of preexisting, and pre-displayed edges). I have played around with a couple of modes of accomplishing this task, but have inevitably run into varied roadblocks.

Here is the code of one of those attempts, that’s only issue (as of right now), is that the slider itself does not display. I used to the basic plotly tutorial on network graphs and simple sliders to help me along.

from mpi4py import MPI
import time
from array import *
import plotly.graph_objects as go
import networkx as nx




def driverFunc():
    nodeChoice = input("How many processes (1 or 8): ")
    if nodeChoice == '1':
        fPath = "/home/datafilepath..."
        dataChoice = input("Which data set would you like to visualize (0-50): ")
        fPath += str(dataChoice) + "/"
        #initialize networkx graph
        inGraph = nx.OrderedGraph()
        nodeArr = []

        #fill node array
        for x in range(1, 101):
            nodeArr.append(x)
        inGraph.add_nodes_from(nodeArr)
        # FUCKFUCKFUCK
        inputD = driverDriver(fPath + "G_0")
        #add initial input edges
        inGraph.add_edges_from(inputD, color='black')
        #position
        pos = nx.spring_layout(inGraph, k=0.99, iterations=20)

        transC = driverDriver(fPath + "dT_0")
        #inGraph.add_edges_from(transC, color='')

        transFin = driverDriver(fPath + "T_0")
        transFinCopy = transFin
        #temporarily remove dupilcate edges, networkx might do this automatically
        for edge in transFin:
            if edge in inputD or edge in transC:
                # print(str(edge) + "OUTTA HERE")
                transFin.remove(edge)

        transC.extend(transFin)
        #print(str(transC))

        #get x and y positions of edges
        edge_x = []
        edge_y = []
        for edge in inGraph.edges():
            edge_x += [pos[edge[0]][0], pos[edge[1]][0], None]
            edge_y += [pos[edge[0]][1], pos[edge[1]][1], None]

        #x and y positions of nodes
        node_x = [pos[k][0] for k in range(1,len(nodeArr))]
        node_y = [pos[k][1] for k in range(1,len(nodeArr))]

        #initial node and edge traces
        node_trace = go.Scatter(
            x = node_x, y= node_y,
            mode = 'markers',
            name = 'net',
            marker=dict(symbol = 'circle-dot',
                        size = 10,
                       color = '#6959CD',
                        line = dict(color='rgb(50, 50, 50)', width=0.5)),
            text = nodeArr,
            hoverinfo = 'text'
        )

        edge_trace = go.Scatter(x = edge_x, y = edge_y, mode = 'lines',
                                line = dict(color = 'black', width =1),
                                hoverinfo = 'none')

        data1 = [edge_trace, node_trace]
        fig1 = go.Figure(data=data1, layout=go.Layout())
        count = 0
        #add different colored traces depending on where in the list one is
        for edge in transC:
            inGraph.add_edge(edge[0], edge[1])
            print(str(edge[0])+' '+str(edge[1]))
            edge_x += [pos[edge[0]][0], pos[edge[1]][0], None]
            edge_y += [pos[edge[0]][1], pos[edge[1]][1], None]

            if count+1 > len(deltaTCopy):
                fig1.add_trace(
                    go.Scatter(
                        x = edge_x[len(edge_x)-1],
                        y = edge_y[len(edge_y)-1],
                        visible = False,
                        line=dict(color='purple', width = 1),
                        hoverinfo = 'all'
                    )
                )
                count+=1
            else:
                fig1.add_trace(
                    go.Scatter(
                        x=edge_x[len(edge_x) - 1],
                        y=edge_y[len(edge_y) - 1],
                        visible=False,
                        line=dict(color='red', width=1),
                        hoverinfo='all'
                    )
                )
                count += 1

        steps = []
        #slider
        for i in range(len(fig1.data)):
            step = dict(
                method='update',
                args=[{'visible':[False]*len(fig1.data)},
                    {'title':"Slider Step: " + str(i)}],
                    #layout attribute
            )
            step["args"][0]["visible"][i] = True #toggle step (i)-th trace to visible
            steps.append(step)
        sliders = [dict(
            active = 10,
            currentvalue = {"prefix": "Step: "},
            pad={"t": len(transC)},
            steps=steps
        )]


        fig1.update_layout(
            sliders = sliders
        )



        fig1.show()



    else:
        fPath = "Data\\396\\D_396_Data_8\\"

    return 0

I know this is a very slow, gross and unoptimized way of going about things, but I’m going for functionality before I work on optimization, and style.

Much appreciated