diagrams
diagrams copied to clipboard
Rendering inline in Databricks notebook
Is there a certain trick to making the below code render inline in a databricks notebook? works fine in jupyter.
from diagrams import Cluster, Diagram
from diagrams.azure.analytics import Databricks
from diagrams.azure.database import DataLake, SQLDatawarehouse
from diagrams.azure.storage import BlobStorage
from diagrams.aws.database import Dynamodb, RDS, Elasticache
from diagrams.aws.analytics import Redshift
from diagrams.aws.storage import S3
node_attr = {
"fontsize":"20"
}
graph_attr = {
"fontsize":"28"
}
with Diagram("", show=False, direction="TB", node_attr=node_attr) as diag:
with Cluster("Azure", graph_attr=graph_attr):
azdatalake = DataLake("\nData Lake\nStorage Gen2")
databricks = Databricks("\nDatabricks")
synapse = SQLDatawarehouse("\nSynapse\nAnalytics")
azdatalake >> databricks
azdatalake >> synapse
with Cluster("AWS", graph_attr=graph_attr):
s3 = S3("\nS3")
databricks = Databricks("\nDatabricks")
redshift = Redshift("\nRedshift")
s3 >> databricks
s3 >> redshift
diag
Not quite the same thing as you were probably expecting, but this is how I do it in Databricks. Make the diagram available in DBFS FileStore, which can be accessed at /files/
. I didn't figure out how to render it from the local driver node.
os.chdir('/dbfs/FileStore')
with Diagram("", show=False, direction="TB", node_attr=node_attr) as diag:
with Cluster("Azure", graph_attr=graph_attr):
azdatalake = DataLake("\nData Lake\nStorage Gen2", )
databricks = Databricks("\nDatabricks")
synapse = SQLDatawarehouse("\nSynapse\nAnalytics")
azdatalake >> databricks
azdatalake >> synapse
with Cluster("AWS", graph_attr=graph_attr):
s3 = S3("\nS3")
databricks = Databricks("\nDatabricks")
redshift = Redshift("\nRedshift")
s3 >> databricks
s3 >> redshift
html = "<img src='/files/diagrams_image.png'>"
displayHTML(html)
Or with IPython
from IPython.display import Image
Image(url='/files/diagrams_image.png')
Thanks. This a decent workaround if there isn't a native solution yet.