cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Warehousing & Analytics
Engage in discussions on data warehousing, analytics, and BI solutions within the Databricks Community. Share insights, tips, and best practices for leveraging data for informed decision-making.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Problem rendering HTML in IPywidgets

vvanag
New Contributor III

The below code works fine in Colab/VSCodium/JupyterNotebook

import ipywidgets as widgets
from IPython.display import display, HTML

output = widgets.Output()

with output:
    display(HTML(some_html))

output

But it does not work in Databricks

testme.html 

2 REPLIES 2

vvanag
New Contributor III
# This works in Colab

import ipywidgets as widgets
from IPython.display import display, HTML

with open('testme.html', encoding='utf8') as f:
    some_html = f.read()

output = widgets.Output()

with output:
    display(HTML(some_html))

output

Ashwin_DSA
Databricks Employee
Databricks Employee

Hi @vvanag,

What youโ€™re seeing is expected to some extent in Databricks Notebooks.

Databricks supports ipywidgets, but it doesnโ€™t guarantee full Jupyter or Colab parity, and there are a few documented limitations on how widgets render and behave in notebooks.

In particular, Databricks notes that some ipywidgets are not supported, widget state is not preserved across notebook sessions, and some widgets or widget outputs may not render correctly in all cases. The docs also specifically note that widgets might not render correctly in dark mode, especially coloured widgets.

A practical workaround is to avoid routing rich HTML through widgets.Output() and instead render the HTML directly in the notebook using Databricks-native HTML rendering, for example, with displayHTML(...). That works better in Databricks when the main goal is to show HTML rather than keep it inside a widget output container.

Here is an example.

%python
import ipywidgets as widgets
from IPython.display import display

btn = widgets.Button(description="Render HTML")

def on_click(_):
    displayHTML(some_html)

btn.on_click(on_click)
display(btn)

Ashwin_DSA_0-1779961551321.png

The public docs here are the best references: Databricks ipywidgets documentation and Known limitations of Databricks notebooks.

Also curious to know if you are using this on serverless or a cluster-backed notebook? Are you using dark mode?Which Databricks Runtime version are you on? Databricks also notes that some ipywidgets do not work in Databricks Runtime 15.0. Lastly, which browser are you testing in? All of these are called out in the limitations and could be causing this.

Hope this helps.

If this answer resolves your question, could you mark it as โ€œAccept as Solutionโ€? That helps other users quickly find the correct fix.

Regards,
Ashwin | Delivery Solution Architect @ Databricks
Helping you build and scale the Data Intelligence Platform.
***Opinions are my own***