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.
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)
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.