Hello everyone! I was wondering, is there a way i...
# questions
f
Hello everyone! I was wondering, is there a way in Kedro to save an altair chart (which is base on vega-lite)? Or do I have to create my own custom dataset? I tried with:
Copy code
blocking_plot:
  type: json.JSONDataset
  filepath: data/06_reporting/blocking_plot.json
  versioned: false
but it does not work.
👀 1
h
Someone will reply to you shortly. In the meantime, this might help:
d
in what way does it not work?
f
Yes, sorry, that wasn't really clear. Unfortunately, my company prevents me from sending screenshots here. It tells me that "Object of type Chart is not JSON serializable", and I understand that it's because it's not only numbers and characters, it's an object of type altair.vegalite.v5.api.Chart. So I guess I would need something like kedro_datasets.plotly.PlotlyDataset, but for vega-lite.
My goal would be to be able to see the plot with kedro-viz
d
can you try adding
<http://chart.to|chart.to>_json()
in your node
f
Ahh, I'll try
d
that being said i think you still need to define a custom previewer fork Kedro Viz https://docs.kedro.org/projects/kedro-viz/en/stable/preview_custom_datasets.html
f
Totally works when I convert to json! But yes, I'll have to define my custom previewer! Thanks, that was really helpful and fast 🤩
d
💪
f
I successfully saved my chart as an HTML file by creating a custom AltairChartDataset dataset. I can therefore open the saved HTML file and view the chart in my browser. However, would be nice to see it directly in Kedro viz, but I'm not sure how to do that by creating a custom previewer. Should I do a PlotlyPreview? How can I tell kedro viz to take the raw HTML file and parse it?
d
@Rashida Kanchwala (for tomorrow) any ideas?
f
It should not be very different from rendering a kedro_datasets.plotly.HTMLDataset in kedro viz. Both are HTML files, so I'm wondering what's the difference.
I'm trying to find the code for PlotlyPreview.
r
Currently we dont support html preview. We could possibly enable it but it would be a feature request and take a bit longer to put it in the code! We do support Images — if there is anyway you could save this as a ‘png’ image or convert it to an image in the preview() function of your custom dataset
d
Oh of course, can you do chat.save() ?
f
Thanks! Yes, with altair, you can save it with chart.save('chart.png'). However, the interactivity in my plot is really important, so I'm going to stick with the HTML (that's not so bad, I can visualize it by opening the file in my file explorer).
👍 1