Skip to content

Databricks notebook renderer #1684

Closed
Closed
@nicolaskruchten

Description

@nicolaskruchten

Right now it seems like the only way to render in Databricks notebook is via displayHTML(fig.to_html()).

From Slack:

Is displayHTML a built-in databricks thing? If so, then this could be done as ExternalRenderer renderer, where the side-effect is calling displayHTML. And we could use the presence of that function in the global namespace to automatically enable the renderer.

Basically identical to BrowserRenderer (

class BrowserRenderer(ExternalRenderer):
"""
Renderer to display interactive figures in an external web browser.
This renderer will open a new browser window or tab when the
plotly.io.show function is called on a figure.
This renderer has no ipython/jupyter dependencies and is a good choice
for use in environments that do not support the inline display of
interactive figures.
mime type: 'text/html'
"""
def __init__(
self,
config=None,
auto_play=False,
using=None,
new=0,
autoraise=True,
post_script=None,
animation_opts=None,
):
self.config = config
self.auto_play = auto_play
self.using = using
self.new = new
self.autoraise = autoraise
self.post_script = post_script
self.animation_opts = animation_opts
def render(self, fig_dict):
from plotly.io import to_html
html = to_html(
fig_dict,
config=self.config,
auto_play=self.auto_play,
include_plotlyjs=True,
include_mathjax="cdn",
post_script=self.post_script,
full_html=True,
animation_opts=self.animation_opts,
default_width="100%",
default_height="100%",
validate=False,
)
open_html_in_browser(html, self.using, self.new, self.autoraise)
)
but calling displayHTML instead of open_html_in_browser. We should probably extract a shared ExternalHtmlRenderer parent class too. Then add an auto-detect section like the colab one in
if not default_renderer:
try:
import google.colab
default_renderer = "colab"
except ImportError:
pass
. But it would check for a NameError on the displayHTML function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions