from graphviz import Graph
import panel as pn
pn.extension(sizing_mode="stretch_width")
This section is independent of Panel. You can find a tutorial and examples in the GraphViz Documentation.
def create_graph(word1="Hello", word2="world", node_color='#00aa41'):
graphviz_graph = Graph(word1, format='svg', node_attr={'color': node_color, 'style': 'filled', "fontcolor": 'white'})
graphviz_graph.attr(bgcolor='#A01346:pink', label='My Awesome Graph', fontcolor='white')
graphviz_graph.edge(word1, word2)
return graphviz_graph
create_graph()
Panel recognizes and shows GraphViz objects in the svg
format out of the box.
word1 = pn.widgets.TextInput(value="Hello", name="Node 1")
word2 = pn.widgets.TextInput(value="World", name="Node 2")
node_color = pn.widgets.ColorPicker(value='#00aa41', name="Node Color")
create_graph = pn.bind(create_graph, word1=word1, word2=word2, node_color=node_color)
create_graph_component = pn.Row(pn.Spacer(), pn.panel(create_graph, width=105, sizing_mode="fixed"), pn.Spacer())
component = pn.Column(word1, word2, node_color, create_graph_component)
component
You can serve the app with panel serve GraphViz.ipynb
an find the live app at http://localhost:5006/GraphViz
pn.template.FastListTemplate(
site="Panel",
site_url="https://panel.holoviz.org/_static/logo_horizontal.png",
title="Graphviz - Basic Example",
main=[component],
).servable();