Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document set_embed_options #2672

Open
joelostblom opened this issue Aug 24, 2022 · 5 comments
Open

Document set_embed_options #2672

joelostblom opened this issue Aug 24, 2022 · 5 comments

Comments

@joelostblom
Copy link
Contributor

@dougthor42
Copy link

For the record, the function itself https://github.com/altair-viz/altair/blob/3e60c99f1ee2b80461a40412e1e0a9689da82f1a/altair/utils/display.py#L39 is documented, but it's just not part of the web docs, likely because the util package is not part of the sphinx docgen.

Though I will say that additional info could be useful. For example, it looks like setting set_embed_options has no effect on the result of the various Chart.to_X methods, which was surprising to me. Any additional documentation might want to include this fact.

>>> import altair as alt
>>> import pandas as pd
>>> df = pd.DataFrame({"x": [1, 2, 3, 4], "y": [1, 2, 3, 4], "name": ["A", "B", "C", "D"]})
>>> chart_wo_embed_opts = alt.Chart(df).mark_circle().encode(x="x:O", y="y:O")
>>> alt.renderers.set_embed_options(actions=False)
RendererRegistry.enable('default')
>>> chart_with_embed_opts = alt.Chart(df).mark_circle().encode(x="x:O", y="y:O")
>>> chart_wo_embed_opts.to_json() == chart_with_embed_opts.to_json()
True

Not sure if this is intended or not. If not, I'll open a separate Issue.

@jakevdp
Copy link
Collaborator

jakevdp commented Aug 25, 2022

embed options do not affect the chart specification, they control the HTML and Javascript code used to display the chart specification in the frontend. That's why we need a weird global config rather than using a chart method that modifies the chart object.

@jakevdp
Copy link
Collaborator

jakevdp commented Aug 25, 2022

You can check the effect like this, for example:

>>> import altair as alt
>>> import pandas as pd
>>> df = pd.DataFrame({"x": [1, 2, 3, 4], "y": [1, 2, 3, 4], "name": ["A", "B", "C", "D"]})
>>> chart = alt.Chart(df).mark_circle().encode(x="x:O", y="y:O")

>>> alt.renderers.set_embed_options(actions=False)
>>> html = chart._repr_mimebundle_()['text/html']  # _repr_mimebundle_ is what JupyterLab uses for rich display
>>> print('"actions": false' in html)
True
>>> print('"actions": true' in html)
False

>>> alt.renderers.set_embed_options(actions=True)
>>> html = chart._repr_mimebundle_()['text/html']
>>> print('"actions": false' in html)
False
>>> print('"actions": true' in html)
True

@dougthor42
Copy link

Thanks for the info - I figured it was intentional but I wanted to confirm.

Searching for set_embed_optoins came about because I'm trying to set some config that can be used for both colab/jupyter and flask+js. What I ended up doing on the flask+sj side was sending both the chart spec and the alt.renderers.options['embed_options'] to my HTML jinja2 template.

daylinmorgan added a commit to daylinmorgan/altair that referenced this issue Oct 1, 2022
@dangotbanned
Copy link
Member

dangotbanned commented Oct 1, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants