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

Type application/vnd.dataresource+json does not produce any visible output #189

Open
Seally opened this issue Dec 25, 2023 · 7 comments
Open
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@Seally
Copy link

Seally commented Dec 25, 2023

I first discovered this issue while trying to use nodejs-polars in a Deno Jupyter kernel. Here's the example code for a notebook cell in Python:

from IPython.display import display

display(
    {
        "application/vnd.dataresource+json": {
            "data": [
                {"continent": "Africa", "total_pop_est": 993281878},
                {"continent": "Antarctica", "total_pop_es": 3802},
                {"continent": "Asia", "total_pop_es": 4085852698},
                {"continent": "Europe", "total_pop_es": 728131201},
                {"continent": "North America", "total_pop_es": 539350981},
                {"continent": "Oceania", "total_pop_es": 33519610},
                {"continent": "Seven seas (open ocean)", "total_pop_es": 140},
                {"continent": "South America", "total_pop_es": 394355478}
            ],
            "schema": {
                "fields": [
                    {"name": "continent", "type": "string"},
                    {"name": "total_pop_est", "type": "integer"}
                ]
            }
        },
        "text/html": "<table><thead><tr><th>continent</th><th>total_pop_est</th></tr></thead><tbody><tr><td>Africa</td><td>993281878</td></tr><tr><td>Antarctica</td><td>3802</td></tr><tr><td>Asia</td><td>4085852698</td></tr><tr><td>Europe</td><td>728131201</td></tr><tr><td>North America</td><td>539350981</td></tr><tr><td>Oceania</td><td>33519610</td></tr><tr><td>Seven seas (open ocean)</td><td>140</td></tr><tr><td>South America</td><td>394355478</td></tr></tbody></table>"
    },
    raw=True
)

Using the text/html presentation works fine. But the application/vnd.dataresource+json presentation does not, and produces basically nothing:

image

VS Code version: 1.85.1
Extension version: 1.0.17
OS: Windows 10

@MasterPtato
Copy link

Same issue here. Looking at the dev tools I see these errors
image

VS Code: 1.85.1
OS: Ubuntu 20.04.1

@scarf005
Copy link

@DonJayamanne since i've been pointed here, may i ask pointers on where to look for in order to fix this issue? I'm interested in opening a PR.

@universalmind303
Copy link

universalmind303 commented Aug 6, 2024

bumping this. It seems like it's using an unmaintained package for handling the datatype.

@DonJayamanne Could we just drop support for this mimetype and let vscode-jupyter fall back to text/html

@soonbro
Copy link

soonbro commented Aug 30, 2024

Hello,
I'm not sure if my comment will be helpful.
I recently discovered Azure Data Studio, which is based on Microsoft's VS Code, and used it for a day.
I noticed that the Notebook feature in Azure Data Studio outputs SQL query results in a grid format.
When I open the resulting .ipynb file in VS Code, the vscode-notebook-renderers extension is set to render the application/vnd.dataresource+json mimetype.
If I use the built-in notebook output renderer in VS Code to display it as text/html, it renders correctly.
However, it doesn't look as nice as it does in Azure Data Studio.

in VS Code
image

in Azure Data Studio
in Azure Data Studio

So, I would like to see support for the application/vnd.dataresource+json mimetype in VS Code, similar to Azure Data Studio.

Thank you!

@Seally
Copy link
Author

Seally commented Aug 30, 2024

So, I would like to see support for the application/vnd.dataresource+json mimetype in VS Code, similar to Azure Data Studio.

@soonbro Technically, vscode-notebook-renderers claims to support application/vnd.dataresource+json on this line:

"application/vnd.dataresource+json",

The problem is that it doesn't work (last I checked). The fact that it lists this at all is why we're getting the blank output. Otherwise, rendering it wouldn't even be an option and only the text/html render will be listed.

I haven't looked too deeply into why it doesn't work. I know this plugin uses some ancient libraries which are no longer maintained. Some aren't even the latest versions of those libraries. Many of the libraries come from the nteract project. In this case, the package with the issue is @nteract/transform-dataresource. I will also add @nteract/data-explorer exists, which seems to be its replacement. It too looks abandoned, but it's still 3 years newer. Also, if I recall correctly, the renderer for application/vnd.dataresource+json in the nteract desktop application does work, which I assume is using data-explorer since the project has it as a dependency and imports it here:

https://github.com/nteract/nteract/blob/7516211c27bad1e5a415505b023e2221bc430d8a/applications/desktop/src/notebook/index.tsx#L24

@SC-CTS
Copy link

SC-CTS commented Sep 27, 2024

For Deno I use the following workaround display function:

// Strip `application/vnd.dataresource+json` from Jupyter display bundle.
// Workaround for: https://github.com/microsoft/vscode-notebook-renderers/issues/189
export const vscd = async (
  obj: unknown,
  options: { raw: boolean; update: boolean; display_id?: string } = { raw: false, update: false }
): Promise<void> => {
  const bundle = (await (obj as any)[Symbol.for('Jupyter.display')]?.()) ?? {};
  const { 'application/vnd.dataresource+json': _json, ...strippedBundle } = bundle;
  const message_type = options.update ? 'update_display_data' : 'display_data';
  const transient = options.display_id ? { display_id: options.display_id } : {};
  Deno.jupyter.broadcast(message_type, { data: strippedBundle, metadata: {}, transient });
  return;
};

and then wrap the object I want to display in vscd(obj). e.g. using nodejs-polars this will then output the HTML table instead.

I guess the same workaround can be done with other kernels as well.

@jmflaherty
Copy link

@SC-CTS, you can change the renderer of the output cell to text/html.
Image
Image
Image

@DonJayamanne DonJayamanne self-assigned this Dec 13, 2024
@DonJayamanne DonJayamanne added the bug Issue identified by VS Code Team member as probable bug label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

8 participants