0

I am using Altair Visualization library for plotting charts in a kaggle kernel. When I run cell by cell, the charts show up. But when I commit the notebook and see the result, the charts are not shown.

I checked the altair version using the alt.version command.

altair verion used in Kaggle

I am using the latest version of altair as per the above result. I even tried adding 'vega' package from settings and committing. Even then, the altair charts were not shown. Not sure what's going wrong.

jakevdp
  • 77,104
  • 11
  • 125
  • 160
Manoj Kumar G
  • 492
  • 8
  • 18

1 Answers1

4

For Altair 2.2 you can use the notebook renderer to make altair charts render:

import altair as alt
alt.renderers.enable('notebook')

Note, however, that these charts will only display when the kernel is live, not when view of the kernel statically (e.g. when sharing a kernel).

In the master branch of Altair, we have just merged a kaggle renderer, and once this makes it into a release (Altair 2.3 or newer) you will be able to use

alt.renderers.enable('kaggle')

and then plots will show in both live and static views of kernels. I have an example of this in action here: https://www.kaggle.com/jakevdp/altair-kaggle-renderer-test

jakevdp
  • 77,104
  • 11
  • 125
  • 160
  • Hi @jakevdp, thanks for your response. I did check that and observed that in one scenario, it is not working. When I use alt.data_transformers.enable('json') for skipping the maxrows error, the charts after enabling the JSON format are not working in Kaggle static view. I had to change the setting to alt.data_transformers.enable('default', max_rows=None) to get our custom Kaggle renderer working. I request you to look into this. – Manoj Kumar G Sep 13 '18 at 04:55
  • The JSON transformer by design breaks the encapsulation of the notebook (storing the data as a file on disk rather than as part of the notebook DOM), so there will never be any way to make it work with the static view. If Kaggle has a way to host a dataset with direct HTTP access, that might be a good route forward – you might ask their support team. – jakevdp Sep 13 '18 at 15:12
  • Thanks @jakevdp. I will try checking with them. – Manoj Kumar G Sep 18 '18 at 10:59