question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Altair graphs wrapped in ipywidgets.Output not being rendered

See original GitHub issue

Dear all,

first of all, thank you for a very nice library that produces beautiful, interactive graphs with very little effort.

We are trying to use these graphs in notebooks served via voila as interactive web applications. We managed to get all the various graphs to show up, when using the kaggle renderer, which will work in both, plain jupyter notebooks (not lab) and voila webapps.

However, when we wrap these graphs into an ipywidget.Output class, there is no more output in neither plain jupyter, nor the voila webapps. An example adapted from the simplemost altair graph I could find is attached below:

from IPython import display
import ipywidgets as widgets
import altair as alt
import pandas as pd

alt.renderers.enable('kaggle',embed_options={'actions': False})

source = pd.DataFrame({
    'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
    'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})

chart = alt.Chart(source).mark_bar().encode(
    x='a',
    y='b'
)
output = widgets.Output()
with output:
    display.display(chart)
output

Being able to wrap graphs into specific outputs is important to control the content that is displayed to the user when serving notebooks as interactive webapps via voila and we were wondering whether there is some way to achieve this behavior?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
joelostblomcommented, Feb 23, 2021

@sradomski I am going through Altair issues to find those that have been resolved and can be closed. Would you be able to close this issue or add a comment if there is something you don’t think is resolved yet?

1reaction
crendlcommented, Oct 22, 2020

I faced the same issue, and can present a workaround:

I use Altair Viewer to display my chart via a local HTTP server, then I create an iframe and pass it on as a widget; e.g:

import altair as alt
import pandas as pd
from IPython.display import display, IFrame
alt.renderers.enable('altair_viewer')

source = pd.DataFrame({
    'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
    'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})

chart = alt.Chart(source).mark_bar().encode(
    x='a',
    y='b'
)
chart

Displaying chart at http: // localhost:19826 /

result = widgets.Output()

scr='http://localhost:19826/'

with result:
    display(IFrame(scr,width=300,height=400))
result

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Display Troubleshooting — Altair 4.2.0 documentation
If you are expecting a chart output and see nothing at all, it means that the Javascript rendering libraries are not being invoked....
Read more >
Altair chart not displaying when evaluated within a function
The reason I want to wrap it in a function is that I have a huge dataset (100 GBs) stored in a database....
Read more >
Reacton — Panel v0.14.2
Panel components have to be wrapped as an ipywidget using the pn.ipywidget wrapper (this requires jupyter_bokeh ).
Read more >
Panel: A high-level app and dashboarding solution for the ...
Wrap the output of your analysis as a Panel “pane”, allowing it to be used together with other Panel components; Connect the individual...
Read more >
10 Heatmaps 10 Python Libraries
This is because matplotlib has the most numerous outputs to render the chart as an image and is natively supported by nbconvert for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found