Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Altair and Panel: Save as button not showing

Tags:

panel

altair

I am using the Python library Altair to plot and let the user save as SVG file. To import data and interactive configuration I wanted to use the Panel library. They integrate well but the button to save is missing when I put the Altair plot inside a Panel element. Other interactivity works fine. This seems to be a general problem as I can find no images of Altair plots inside a Panel element having the save button. However, I cannot find anybody addressing this specific issue, so the question is there any way to resurrect the button so the user can save?

(I know about altair_saver for programmatically saving, but unfortunately we cannot allow the dependencies on our system)

Here is a simple example of Altair with and without Panel. enter image description here

And here is the code:

import pandas as pd
import altair as alt
alt.__version__

import panel as pn
pn.extension('vega')
pn.__version__

dictdata = {'variable': ['A', 'B', 'C', 'D'], 'value': [1, 3, 2, 4] }
df = pd.DataFrame.from_dict(dictdata)

chart = alt.Chart(df).mark_bar().encode(
   y = alt.Y('variable:N'),
   x = alt.X('value:Q'),
)
chart

pn.Row(chart)
like image 968
timthoe Avatar asked Nov 20 '25 19:11

timthoe


1 Answers

This "save button" is known as the actions menu, and is configurable in vega-embed with the actions option.

Panel's vega chart embedding explicitly removes the actions by setting {actions: false}, as seen here: panel/models/vega.ts#L71.

Unfortunately, it does not appear that the package offers any way to configure this. You might try submitting a feature request to the Panel library.

like image 117
jakevdp Avatar answered Nov 23 '25 19:11

jakevdp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!