Order of output mime types not respected by Notebook Output renderer
See original GitHub issueDoes this issue occur when all extensions are disabled?: Yes/No
- VS Code Version: Stable
- OS Version: Any
Steps to Reproduce:
- Create a Jupyter notebook with the following content
Sample ipynb file
{
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"application/json": {
"hello": 134
},
"text/html": [
"<div>1234</div><ul><li>1</li><li>2</li><li>3</li></ul>"
],
"text/plain": [
"<__main__.Something at 0x131c3d5b0>"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"class Something():\n",
"\tone = 1234\n",
"\tdef _repr_html_(self):\n",
"\t\treturn '<div>1234</div><ul><li>1</li><li>2</li><li>3</li></ul>'\n",
"\n",
"\tdef _repr_json_(self):\n",
"\t\treturn {'hello':134}\n",
"\n",
"\n",
"Something()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.13 ('.venvWidgets': venv)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
- Open the file in VS Code
- The JSON output is displayed instead of HTML, this is wrong, the HTML output is richer and should be given preference
@connor4312 @mjbvz based on the code we seem to have some preference hardcoded in VS Code for mime types See here https://github.com/microsoft/vscode/blob/issue164304/src/vs/workbench/contrib/notebook/common/notebookCommon.ts#L43
export const NOTEBOOK_DISPLAY_ORDER: readonly string[] = [
'application/json',
'application/javascript',
'text/html',
'image/svg+xml',
Mimes.latex,
Mimes.markdown,
'image/png',
'image/jpeg',
Mimes.text
];
I’m not entirely sure why this is there or what what it does, but my understanding of display order of mime types was:
- Extension needs to sort the output items in the order we would like them displayed. I.e. if the output has 2 mime types, then exnesion needs to ensure the mime types are sorted so that the first item is displayed.
Right now this results in a poor UX as users cannot see the HTML output instead end up with JSON which doesn’t necesssarily contain the best output for viewing.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Handling of "repeated" mime types in notebook output #124357
We handle the "separate output, same MIME type"-case correctly because we show both outputs at the same time, but for the "single output, ......
Read more >MIME type warning when plotting data with R in a Jupyter ...
Every time I plot data with R (IRKernel) into a Jupyter notebook I get a warning message that says "No renderer could be...
Read more >Working with Jupyter code cells in the Python Interactive window
View, inspect, and filter variables using the Variables Explorer and Data Viewer; Connect to a remote Jupyter server; Debug a Jupyter notebook; Export...
Read more >The Notebook | Query and analyze data - Mode Support
Overview. Every Mode report contains an integrated notebook-style environment where analysts can extend their analysis using either Python or R.
Read more >Messaging in Jupyter — jupyter_client 7.4.8 documentation
The handling of these out-of-order output messages is currently undefined in this specification, but the Jupyter Notebook continues to handle IOPub messages ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I also don’t have any context on this. Let’s revisit it in November
I agree that this seems outside the responsibility of the serializer to know about. Not having worked with the notebook API in a little while and just looking at it, it doesn’t look like a notebook type even needs a serializer. I think json should be just above ‘text’ at the end of the prioritization list, however.
In testing’s API, I had a similar use case around the TestRunProfile. In that case allowed extensions to set
isDefault
on a profile to determine if that profile should be used to run tests by default, provided the user hasn’t chosen different profile(s) for that test controller already. If API is warranted for notebooks here, adding a similar flag onNotebookCellOutputItem
’s might be a more minimal approach than a priority list, and also allows extensions to control display on a per-output basis.