-
Notifications
You must be signed in to change notification settings - Fork 506
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
yaml display using IPython.display.Markdown works JupyterLab but not Voila #1159
Comments
You cannot display new outputs in Voila, you'll need to embed your Markdown in an output widget for this to work, see similar issue #1145 |
i'm not sure that was the issue... i tried the below, i.e. loading all the markdown into Output widgets initially, which still didn't work: (i may have misunderstood your point here?) from IPython.display import Markdown, clear_output
from ipywidgets import ToggleButton, Output
import json
import yaml
STR_JSON="""{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}"""
PARSED = json.loads(STR_JSON)
OUT1 = Output()
with OUT1:
s = yaml.dump(PARSED, indent=2)
display(Markdown("YAML displays in JupyterLab but not in Voila"))
display(Markdown("\n```yaml\n" + s + "\n```"))
OUT2 = Output()
with OUT2:
s = json.dumps(PARSED, indent=2)
display(Markdown("\n```Python\n" + s + "\n```"))
def _on_change(change):
with out:
clear_output()
if as_yaml.value:
display(OUT1)
else:
display(OUT2)
out = Output()
as_yaml = ToggleButton(description='as_yaml?')
as_yaml.observe(_on_change, names='value')
as_yaml.value=True
display(as_yaml)
display(out) in the end I just used the rich console rather the IPython display system, which worked in both JupyterLab and Voila: from IPython.display import clear_output #Markdown,
from ipywidgets import ToggleButton, Output
import json
import yaml
from rich.console import Console, COLOR_SYSTEMS
from rich.markdown import Markdown
STR_JSON="""{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}"""
PARSED = json.loads(STR_JSON)
OUT1 = Output()
with OUT1:
s = yaml.dump(PARSED, indent=2)
display(Markdown("YAML displays in JupyterLab and Voila using the rich console"))
console = Console(style="white")
console.print(Markdown("\n```yaml\n" + s + "\n```"))
OUT2 = Output()
with OUT2:
s = json.dumps(PARSED, indent=2)
display(Markdown("\n```Python\n" + s + "\n```"))
def _on_change(change):
with out:
clear_output()
if as_yaml.value:
display(OUT1)
else:
display(OUT2)
out = Output()
as_yaml = ToggleButton(description='as_yaml?')
as_yaml.observe(_on_change, names='value')
as_yaml.value=True
display(as_yaml)
display(out) |
Sorry I read a bit fast your initial issue. There might be something else here that I missed. I'll have a deeper look. |
Would you be able to try with Voila v0.5.0a4? That may just work 🤞🏽 |
This should be fixed by #1353 |
likely related too:
#873
#166
Description
display markdown yaml works in JupyterLab but not in Voila
Reproduce
Expected behavior
Expect what happens in JuptyerLab
Context
If using JupyterLab
Installed Labextensions
The text was updated successfully, but these errors were encountered: