A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
Altair embed options to remove actions (#7277)
vincent d warmerdam99b9858a07f8
diff --git a/frontend/src/plugins/impl/vega/VegaPlugin.tsx b/frontend/src/plugins/impl/vega/VegaPlugin.tsxindex c6f9755ff1..e83a80ac75 100644--- a/frontend/src/plugins/impl/vega/VegaPlugin.tsx+++ b/frontend/src/plugins/impl/vega/VegaPlugin.tsx@@ -24,6 +24,7 @@ export class VegaPlugin implements IPlugin<VegaComponentState, Data> {.union([z.boolean(), z.literal("point"), z.literal("interval")]).default(true),fieldSelection: z.union([z.boolean(), z.array(z.string())]).default(true),+ embedOptions: z.object({}).passthrough().default({}),});render(props: IPluginProps<VegaComponentState, Data>): JSX.Element {diff --git a/frontend/src/plugins/impl/vega/vega-component.tsx b/frontend/src/plugins/impl/vega/vega-component.tsxindex 55ad1c7c17..4ed6a03825 100644--- a/frontend/src/plugins/impl/vega/vega-component.tsx+++ b/frontend/src/plugins/impl/vega/vega-component.tsx@@ -33,6 +33,7 @@ export interface Data {spec: VegaLiteSpec;chartSelection: boolean | "point" | "interval";fieldSelection: boolean | string[];+ embedOptions?: Record<string, unknown>;}export interface VegaComponentState {@@ -60,6 +61,7 @@ const VegaComponent = ({chartSelection,fieldSelection,spec,+ embedOptions,}: VegaComponentProps<VegaComponentState>) => {const { data: resolvedSpec, error } = useAsyncData(async () => {// We try to resolve the data before passing it to Vega@@ -84,6 +86,7 @@ const VegaComponent = ({chartSelection={chartSelection}fieldSelection={fieldSelection}spec={resolvedSpec}+ embedOptions={embedOptions}/>);};@@ -94,12 +97,35 @@ const LoadedVegaComponent = ({chartSelection,fieldSelection,spec,+ embedOptions,}: VegaComponentProps<VegaComponentState>): JSX.Element => {const { theme } = useTheme();const vegaRef = useRef<HTMLDivElement>(null);const vegaView = useRef<View>(undefined);const [error, setError] = useState<Error>();+ // Merge default actions with user-provided embed options+ const actions = useMemo(() => {+ // If embedOptions contains 'actions', use it directly+ if (embedOptions && "actions" in embedOptions) {+ return embedOptions.actions as+ | boolean+ | {+ export?: boolean;+ source?: boolean;+ compiled?: boolean;+ editor?: boolean;+ }+ | undefined;+ }++ // Otherwise use defaults+ return {+ source: false,+ compiled: false,+ };+ }, [embedOptions]);+// Aggressively memoize the spec, so Vega doesn't re-render/re-mount the componentconst specMemo = useDeepCompareMemoize(spec);const selectableSpec = useMemo(() => {@@ -289,11 +315,6 @@ const LoadedVegaComponent = ({);};-const actions = {- source: false,- compiled: false,-};-/*** Convert any sets to a list before passing to the BE*/diff --git a/marimo/_plugins/ui/_impl/altair_chart.py b/marimo/_plugins/ui/_impl/altair_chart.pyindex b57d5c38bf..50882fa75f 100644--- a/marimo/_plugins/ui/_impl/altair_chart.py+++ b/marimo/_plugins/ui/_impl/altair_chart.py@@ -428,6 +428,11 @@ class altair_chart(UIElement[ChartSelection, ChartDataType]):import altair as alt+ # Capture any global altair embed options that may have been set+ embed_options = {}+ if alt.renderers.options.get("embed_options"):+ embed_options = alt.renderers.options["embed_options"]+register_transformers()# Make a copy@@ -539,6 +544,7 @@ class altair_chart(UIElement[ChartSelection, ChartDataType]):"spec": vega_spec,"chart-selection": chart_selection,"field-selection": legend_selection,+ "embed-options": embed_options,},on_change=on_change,)