-
Notifications
You must be signed in to change notification settings - Fork 297
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
Render stored Matplotlib png output as a fallback when opening a notebook #8635
Comments
See jupyter/notebook#6181 for the approach we took in Jupyter Notebook: do a try/catch of the mimetype rendering logic, so that if the mimetype renderer fails to render, we fallback to another available mimetype. |
Thanks for the bug. VS code doesn't allow for a fallback mimetype. On reload it just uses the widget data as that's what was selected before. We don't support reloading widgets at the moment (see this bug for more info: #5424 (comment)) |
Solution
|
Summary of discussion with @mjbvz
|
@mjbvz I can see another case for fallbacks:
from vega import VegaLite
from IPython.display import display
display({
"application/vnd.vegalite.v4+json": {
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "A simple bar chart with embedded data.",
"data": {
"values": [
{"a": "A", "b": 28}, {"a": "B", "b": 55}, {"a": "C", "b": 43},
{"a": "D", "b": 91}, {"a": "E", "b": 81}, {"a": "F", "b": 53},
{"a": "G", "b": 19}, {"a": "H", "b": 87}, {"a": "I", "b": 52}
]
},
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "nominal", "axis": {"labelAngle": 0}},
"y": {"field": "b", "type": "quantitative"}
}
}}, raw=True)
TLDR:I believe we (VS Code) should also do the same thing, instead of displaying a message saying |
@rebornix To support this, we need to transfer the entire output to the webview. Today I believe we just send over the output for the selected item mime type That would allow us to fallback to a different renderer if we can't find one for the current mime type Let's look into this for October |
Scenraios1. Sharing Notebook
2. Opening existing notebook
ExpectationIf IPYWidget otuput cannot be displayed, then display the HTML or next available mime Problems encounteredFor scenario 1, things work most of the time with the new API provided by Matt. However in Scenario 2 it will fail to work 100% of the time.
In the case of Scenario 2, when the notebook is re-opened
SolutionWe need to check whether the IPyWidget Id belongs to the active kernel session or not, and if it does not, then assume that it will not get rendered.
|
Actual behaviour
With the current ipympl and using
%matplotlib widget
as a backend VS code can render this example without issues:Though, when saving and reloading the notebook file no image is shown (although a static image is available):
Expected behaviour
The small
</>
icon on the left allows to change the mimetype representation. When this is changed manually topng
the alternative widget representation that was previously saved is shown correctly:So VS code does not recognize that without a running/current widget available that the
png
static representation should be shown instead.Environment data
The text was updated successfully, but these errors were encountered: