Skip to content

Commit

Permalink
Merge pull request #3278 from c-chaitanya/chromium-browser-renderer-fix
Browse files Browse the repository at this point in the history
fix for chromium renderer on linux systems (issue #2348)
  • Loading branch information
nicolaskruchten authored Jul 21, 2021
2 parents ab622e3 + 712684c commit 2c2dd6a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/python/plotly/plotly/io/_base_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,16 @@ def open_html_in_browser(html, using=None, new=0, autoraise=True):
if isinstance(html, six.string_types):
html = html.encode("utf8")

if isinstance(using, tuple):
try:
using = [i for i in webbrowser._browsers.keys() if i in using][0]
except IndexError:
raise ValueError(
"""
Unable to find the given browser.
Try one among the following 'chrome', 'chromium', 'firefox' or 'default' """
)

class OneShotRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
Expand Down
8 changes: 5 additions & 3 deletions packages/python/plotly/plotly/io/_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,11 @@ def show(fig, renderer=None, validate=True, **kwargs):

# External
renderers["browser"] = BrowserRenderer(config=config)
renderers["firefox"] = BrowserRenderer(config=config, using="firefox")
renderers["chrome"] = BrowserRenderer(config=config, using="chrome")
renderers["chromium"] = BrowserRenderer(config=config, using="chromium")
renderers["firefox"] = BrowserRenderer(config=config, using=("firefox"))
renderers["chrome"] = BrowserRenderer(config=config, using=("chrome", "google-chrome"))
renderers["chromium"] = BrowserRenderer(
config=config, using=("chromium", "chromium-browser")
)
renderers["iframe"] = IFrameRenderer(config=config, include_plotlyjs=True)
renderers["iframe_connected"] = IFrameRenderer(config=config, include_plotlyjs="cdn")
renderers["sphinx_gallery"] = SphinxGalleryHtmlRenderer()
Expand Down
3 changes: 3 additions & 0 deletions packages/python/plotly/plotly/tests/test_io/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest
import requests
import numpy as np
import webbrowser

import plotly.graph_objs as go
import plotly.io as pio
Expand Down Expand Up @@ -224,6 +225,8 @@ def test_notebook_connected_show(fig1, name, connected):
def test_browser_renderer_show(fig1, renderer):
pio.renderers.default = renderer
renderer_obj = pio.renderers[renderer]
# scan through webbrowser._browsers.keys() and assign the browser name registered with os
renderer_obj.using = [i for i in webbrowser._browsers.keys() if renderer in i][0]

# Setup mocks
mock_get = MagicMock(name="test get")
Expand Down

0 comments on commit 2c2dd6a

Please sign in to comment.