0

I've a simple bokeh layout with a textinput and button. When button is clicked, depending on the textinput.value, two plots need to be created.

Plot 1 is a networkx Digraph and Plot 2 is a timeseries of prices. Here's what I tried:

ask_input = TextInput(placeholder="Search", width = 500, height=100)
ask_button = Button(label="GET", width = 100, height=50)
ask_button.on_click(addPlots)

layout = layout([[widgetbox(ask_input, ask_button)]])
curdoc().add_root(layout)

def addPlots():    
     p1=buildGraph()
     p2=buildPlot()
     layout.children[-1].children.append(row([p1],[p2]))

def buildGraph():
     for i in range(len(graph_matrix)):
            client_graph.add_edge(green_nodes[i], orange_nodes[i], weight=weights[i])

    node_size=5000
    pos=nx.spring_layout(client_graph)    

    node_colors = ['green' if node in green_nodes.unique() else 'orange'
           for node in client_graph.nodes()]
    nx.draw_networkx_edges(client_graph, pos, arrows=True)

    nx.draw_networkx_nodes(client_graph, pos,with_labels=True, arrows = True, node_size=node_size, node_color=node_colors)
    nx.draw_networkx_labels(client_graph, pos, font_size=15,font_family='CONSOLAS', with_labels=True, arrows=True)
    #this is where there maybe a disconnect between the graph and the plot
    fig = figure(title='Connections')
    return fig

def buildPlot():
    fig2=stock_df.plot('adj_close',data=stock_df) #against a DateTimeIndex
    return fig2

The error is that a non-LayoutDOM object cannot be inserted into the row. Am sure am not adding the graph/plot to the figure right. Can networkx graphs be added to a plot?

1 Answer 1

1

The short answer is "no". Or at least, not in the way you are attempting. Bokeh layouts can only contain other Bokeh objects, e.g. the plots, gmap plots, data tables and widgets that are part of the Bokeh library. Bokeh does not know anything at all about networkx output. It's not something Bokeh can put directly in one of its own layouts. As of Bokeh 0.12.6 you have a couple of options:

Without more the larger context of what you are trying to do its hard ot be more specific, or say which approach might be better.


Please note that for 0.12.7 there will be better support for passing graph/network data directly, see this open PR:

https://github.com/bokeh/bokeh/pull/6544

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.