Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Superfluous plots and errors with Python HTML outputs that inject dependencies #1719

Open
jmcphers opened this issue Oct 30, 2023 · 2 comments
Assignees

Comments

@jmcphers
Copy link
Collaborator

To reproduce, try running this example (from itables):

import itables
from itables import init_notebook_mode
from itables import show

init_notebook_mode(all_interactive=True)

import world_bank_data as wb

df = wb.get_countries()
df
show(df)

This should create an interactive Jupyter table in the Viewer pane. Instead, we get this nonsense in the Plots pane:

image

The problem here is that itables uses init_notebook_mode to inject dependencies; in this case, a <script> tag that loads the necessary JavaScript libraries.

Later, when you run show(df), the itable is supposed to be rendered, like this. The render step presumes that the scripts injected by the dependency step (i.e. init_notebook_mode) are already loaded in the notebook.

image

But in Positron, there are two distinct issues that keep this from working:

  1. Positron doesn't know what to do with the dependencies; they are emitted as plain HTML, so we try to render them like a plot. Of course, they aren't a plot, and errors ensue.
  2. When Positron attempts to render the table, it does so in a clean webview that does not have the dependencies loaded. Consequently, the render fails, too.

So this simple example generates two or three busted outputs in Positron. I'm not sure the best way to address this, but it could look something like:

  • analyze the HTML of text/html output to see if it contains any renderable content or just scripts
  • if it's all scripts, add (or amend) its content to a global
  • when rendering text/html output, inject the contents of the global into the <head> tag.
@testlabauto
Copy link
Contributor

This now goes to the viewer pane but looks good.

Image

@testlabauto
Copy link
Contributor

It does work in a notebook, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants