cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to display markdown output in databricks notebook from a python cell

Dan-K
New Contributor III

With IPython/Jupyter it's possible to output markdown using the IPython display module and its `MarkDown`class.

Example markdown output 

Question

How can I accomplish this with Azure Databricks?

What I tried

Databricks `display`

Tried using Databrick's display with the IPython Markdown class:

from IPython.display import Markdown
display(Markdown('*some markdown* test'))

but this results in the following error:

Exception: Cannot call display(<class 'IPython.core.display.Markdown'>)

IPython `display`

I then tried to use IPython's display:

from IPython.display import display, Markdown
display(Markdown('*some markdown* test'))

but this just displays the text:

<IPython.core.display.Markdown object>

Example failed ouput 

IPython `display_markdown`

Tried using IPython's `display_markdown`:

from IPython.display import display_markdown
display_markdown('# Markdown is here!\n*some markdown*\n- and\n- some\n- more')

but this results in nothing showing up:

Failed display_markdown 

Looking up documentation

Also tried checking Azure Databricks documentation. At first I visited https://www.databricks.com/databricks-documentation which leads me to https://docs.microsoft.com/en-ca/azure/databricks/ but I wasn't able to find anything via searching or clicking the links and I usually find Microsoft documentation quite good. However, according to this page, Databricks is using IPython kernel so I guess it's unclear what portions of IPython can be used and which cannot.

Checking Databrick's `display` source

According to Databrick's source for the `display` function, it will readily render any object that implements `_repr_html()`.

Databricks displayHowever I'm having a hard time being able to get the raw html output that I'm assuming `IPython.display.Markdown` should be able to output. I can only find `_repr_markdown_()` and `_data_and_metadata()` where the former just calls the latter and the output, at least in Databricks, is just the original raw markdown string.

1 ACCEPTED SOLUTION

Accepted Solutions

Dan-K
New Contributor III

Sorry but you misunderstood my question. I put so much detail into it too ๐Ÿ˜…

I want markdown in the output of a python cell. Not a markdown cell.

I found a workaround on stack overflow which works, but this requires importing the markdown library:

Screenshot 2022-09-02 175227Is there a way to create a feature request for this sort of thing to be supported natively in databricks (like it is in jupyter)?

View solution in original post

6 REPLIES 6

Debayan
Databricks Employee
Databricks Employee

Hi, Thanks for reaching out to community.databricks.com.

In a notebook cell, type "%md" and type some markdown and it will render.

Please refer: https://community.databricks.com/s/question/0D53f00001HKHhNCAX/markup-in-databricks-notebook

Dan-K
New Contributor III

Sorry but you misunderstood my question. I put so much detail into it too ๐Ÿ˜…

I want markdown in the output of a python cell. Not a markdown cell.

I found a workaround on stack overflow which works, but this requires importing the markdown library:

Screenshot 2022-09-02 175227Is there a way to create a feature request for this sort of thing to be supported natively in databricks (like it is in jupyter)?

Debayan
Databricks Employee
Databricks Employee

@Daniel Khodabakhshโ€‹  I would request to file a feature request in our ideas portal https://ideas.databricks.com/ideas/, so that you can interact and receive the updates directly with PM team. The ideas portal allows the customers to submit enhancement ideas and other customers to vote on their submitted ideas, and also gives the customers a direct line of communication with PM. You can subscribe to status updates as well.

Dan-K
New Contributor III

Sweet! Thanks @Debayan Mukherjeeโ€‹, , I think I'll go ahead and do that ๐Ÿ‘

Dan-K
New Contributor III

Hey @Debayan Mukherjeeโ€‹ I tried accessing the link you provided but it redirects me to a page asking me to enter the workspace domain.

Which workspace domain do I use if I'm using Azure Databricks? I tried 'azure' but this didn't work.

Debayan
Databricks Employee
Databricks Employee

@Daniel Khodabakhshโ€‹ If you are signing in to the ideas portal for the very first time, could you please refer this https://docs.databricks.com/delegated-auth.html#sign-in-to-the-ideas-portal-the-first-time.

Please let us know if you need further clarification on the same.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group