Conversation

pfalcon

In my virtual environment, there happens to be installed IPython package. It wasn't installed by myself, it's merely a transitive dependency of some another package. It's neither intended to be used, nor is actually used by my project. However, mere presense of the IPython package, due to the over-simplistic decision code in this module (io._renderers) leads to drastic behavior change in Plotly.py: calling Figure.repr_html() causes lots of JS garbage to be printed on terminal (by common sense, this should be a side-effects free function, only returning a value). On a higher level, this breaks natural Plotly.py integration in frameworks like Shiny.py (because again, instead of HTML representation being returned for a framework to process, parts of that representation are dumped on terminal).

The real underlying issue is that Plotly.py should not force-import any "optional" packages behind users' back. However, this is a deeper issue requiring consideration and will be reported separately. This is a quick solution for the problem describe above.

From interactive session:

>>> import IPython
>>> IPython.get_ipython().__class__.__name__
'NoneType'

Code PR

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the codegen files and not generated files.
  • I have added tests (if submitting a new feature or correcting a bug) or
    modified existing tests.
  • For a new feature, I have added documentation examples in an existing or
    new tutorial notebook (please see the doc checklist as well).
  • I have added a CHANGELOG entry if fixing/changing/adding anything substantial.
  • For a new feature or a change in behaviour, I have updated the relevant docstrings in the code to describe the feature or behaviour (please see the doc checklist as well).

In my virtual environment, there happens to be installed IPython package.
It wasn't installed by myself, it's merely a transitive dependency of
some another package. It's neither intended to be used, nor is actually
used by my project. However, mere presense of the IPython package, due
to the over-simplistic decision code in this module (io._renderers)
leads to drastic behavior change in Plotly.py: calling
Figure._repr_html_() causes lots of JS garbage to be printed on terminal
(by common sense, this should be a side-effects free function, only
returning a value). On a higher level, this breaks natural Plotly.py
integration in frameworks like Shiny.py (because again, instead of
HTML representation being returned for a framework to process, parts
of that representation are dumped on terminal).

The real underlying issue is that Plotly.py should not force-import
any "optional" packages behind users' back. However, this is a deeper
issue requiring consideration and will be reported separately. This
 is a quick solution for the problem describe above.

From interactive session:

>>> import IPython
>>> IPython.get_ipython().__class__.__name__
'NoneType'

Signed-off-by: Paul Sokolovsky <[email protected]>
@pfalcon

Example of how this affects downstream projects: posit-dev/py-shinywidgets#201 . I'm an experienced Python user, and it took me half a day to debug this issue. I imagine how frustrating it may be for novice users who just wanted to try one of those well-popularized modern Python data visualization packages.

@gvwilsongvwilson requested a review from emilykl June 13, 2025 14:12
@gvwilsongvwilson addedsomething newP1needed for current cyclecommunitycommunity contributionlabels Jun 13, 2025
Sign up for free to join this conversation on . Already have an account? Sign in to comment
communitycommunity contributionfeaturesomething newP1needed for current cycle
None yet

Successfully merging this pull request may close these issues.