posit-dev / py-htmltools

Tools for HTML generation and output
MIT License
19 stars 2 forks source link

show() method with "auto" does not produce anything in IPython console #80

Open machow opened 8 months ago

machow commented 8 months ago

When run in jupyterlab, the TagList.show() method produces html output. However, when run from an ipython console session (e.g. when running ipython from your terminal), nothing happens.

It seems like the culprit is this line, which does not distinguish between the console and notebook/lab:

            ipy = (  # pyright: ignore[reportUnknownVariableType]
                IPython.get_ipython()  # pyright: ignore[reportUnknownMemberType]
            )
            renderer = "ipython" if ipy else "browser"

In plotly, it appears they detect the console by running this code:

ipython.get_ipython().__class__.__name__ == "TerminalInteractiveShell"

It seems like the code above would allow auto htmltools to set renderer to "browser" when in an ipython session.

Related to https://github.com/posit-dev/great-tables/issues/100