Skip to content

docs: altair component page#326

Open
chendaniely wants to merge 33 commits into
mainfrom
components-output-altair
Open

docs: altair component page#326
chendaniely wants to merge 33 commits into
mainfrom
components-output-altair

Conversation

@chendaniely

@chendaniely chendaniely commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

Adds a new Altair output component page. I also added a reference in the Jupyter Widgets Concepts page to the altair output.
My goal for the components page is to provide an altair, jupyterchart, and shiny example for all the ones in the altair jupyterchart docs page.
Not all of the examples are reproduced, some are redundant (like the observe results) and others like the ipywidgets.link() aren't supported by shinywidgets

Relevant conversations:

Documentation references:

@chendaniely chendaniely changed the title altrair core and express apps docs: altair component page Nov 26, 2025
@github-actions
github-actions Bot temporarily deployed to pr-326 November 26, 2025 03:54 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-326 December 2, 2025 03:59 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-326 December 3, 2025 07:29 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-326 December 3, 2025 08:14 Destroyed
@github-actions
github-actions Bot temporarily deployed to pr-326 December 3, 2025 08:19 Destroyed
@chendaniely
chendaniely requested a review from Copilot December 3, 2025 16:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive documentation for using Altair (Vega-Altair) interactive visualizations in Shiny for Python applications. The documentation includes both Express and Core syntax examples, along with three interactive variations demonstrating different selection types.

Key changes:

  • Added complete Altair component documentation page with detailed usage instructions
  • Provided example apps for both Express and Core syntax
  • Included three variation examples: hover point selection, brush (interval) selection, and legend point selection

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
images/altair.png Screenshot/preview image for the Altair component documentation
components/outputs/plot-altair/index.qmd Main documentation page explaining Altair integration, API references, and usage details
components/outputs/plot-altair/app-express.py Basic Express syntax example showing filtered bar chart
components/outputs/plot-altair/app-core.py Basic Core syntax example showing filtered bar chart
components/outputs/plot-altair/app-variation-hover-point-express.py Express example demonstrating IndexSelection with hover interactions
components/outputs/plot-altair/app-variation-hover-point-core.py Core example demonstrating IndexSelection with hover interactions
components/outputs/plot-altair/app-variation-brush-express.py Express example demonstrating IntervalSelection with brush interactions
components/outputs/plot-altair/app-variation-brush-core.py Core example demonstrating IntervalSelection with brush interactions
components/outputs/plot-altair/app-variation-point-express.py Express example demonstrating PointSelection with legend binding
components/outputs/plot-altair/app-variation-point-core.py Core example demonstrating PointSelection with legend binding

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread components/outputs/plot-altair/index.qmd Outdated
Comment thread components/outputs/plot-altair/index.qmd Outdated
Comment thread components/outputs/plot-altair/app-variation-selection-interval-brush-express.py Outdated
Comment thread components/outputs/plot-altair/app-variation-selection-interval-brush-core.py Outdated
Comment thread components/outputs/plot-altair/index.qmd Outdated
Comment thread components/outputs/plot-altair/app-variation-selection-interval-brush-express.py Outdated
Comment thread components/outputs/plot-altair/app-variation-selection-index-hover-core.py Outdated
Comment thread components/outputs/plot-altair/app-variation-selection-index-hover-express.py Outdated
Comment thread components/outputs/plot-altair/app-variation-selection-index-hover-express.py Outdated
chendaniely and others added 6 commits December 4, 2025 08:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…l-brush-express.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…over-express.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…over-core.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…over-express.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment on lines +155 to +156
:::{#relevant-functions}
:::

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the output_plot/render_plot. Add output_widget

Screenshot 2025-12-04 at 2 18 00 PM

Comment on lines +152 to +153
:::{#example}
:::

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if the code block had a lightning bolt to open in shinylive -- like the plotly component page does

Screenshot 2025-12-04 at 2 15 11 PM

Comment thread docs/jupyter-widgets.qmd
Some widgets have attributes that _contain_ observable traits.
One practical example of this is the `selections` attribute of altair's `JupyterChart` class, which has an [observable `point` trait](https://altair-viz.github.io/user_guide/interactions/jupyter_chart.html#point-selections).

For more information about Shiny, Alatir, and JupyterChart, see the [Altair components page](/components/outputs/plot-altair/index.qmd).

@cpsievert cpsievert Dec 4, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should feature this more prominently (perhaps in a callout) at the bottom of the ## Get Started section?

@@ -0,0 +1,220 @@
---
title: Plot (Altair)
sidebar: components

@cpsievert cpsievert Dec 4, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Altair doesn't seem to be showing up in the sidebar

Screenshot 2025-12-04 at 2 14 19 PM


To make an Altair figure, we need to do the following steps:

::: {.panel-tabset group="syntax"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
::: {.panel-tabset group="syntax"}
::: {.panel-tabset .shiny-mode-tabset group="shiny-app-mode"}

::: {.panel-tabset group="syntax"}
## Express

1. Import the `render_altair()` functions from `shinywidgets`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Import the `render_altair()` functions from `shinywidgets`.
1. Import `render_altair` from `shinywidgets`.

Comment on lines +174 to +179
2. Define a function where you want to create the figure.
- If your function calls reactive values, Shiny will update your figure whenever those values change, in a [reactive fashion](https://shiny.posit.co/py/docs/reactive-programming.html).
- Do not forget to return the plot object from your function.

3. Decorate your plotting function with a `@render_altair()` decorator.
- If your plotting function is not the same as the `id` you used in the `ui.output_widget()`, you can add an additional `@output(id=...)` decorator.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. Define a function where you want to create the figure.
- If your function calls reactive values, Shiny will update your figure whenever those values change, in a [reactive fashion](https://shiny.posit.co/py/docs/reactive-programming.html).
- Do not forget to return the plot object from your function.
3. Decorate your plotting function with a `@render_altair()` decorator.
- If your plotting function is not the same as the `id` you used in the `ui.output_widget()`, you can add an additional `@output(id=...)` decorator.
2. Define a function that returns an `altair.Chart`
3. Decorate that function with a `@render_altair`
- This decorator lets Shiny know to automatically update the chart when it's [reactive](../../../docs/reactive-programming.Rmd) dependencies (e.g., [inputs](../../#inputs)) change

- If your plotting function is not the same as the `id` you used in the `ui.output_widget()`, you can add an additional `@output(id=...)` decorator.
:::

To learn more about using Jupyter widgets with Shiny visit: [shiny.posit.co/py/docs/jupyter-widgets.html](https://shiny.posit.co/py/docs/jupyter-widgets.html).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should come towards the end of the article (and mention that altair is just example of a Jupyter widget in Shiny)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, now I see we do this for Plotly -- I guess it's not super important, but ideally we'd have something better on both pages.

Related to this, a stretch goal (for both components) would be to have a few more "basic" variations before diving into the more complex "plots as inputs" and "plot mutation" concepts.

I also think a link to plotly/atair galleries at this point might be more useful than a link to the generic Jupyter Widgets article.

we will need to use the [`shinywidgets`](https://shiny.posit.co/py/docs/jupyter-widgets.html)
library to connect Shiny with [`ipywidgets`](https://ipywidgets.readthedocs.io/en/latest/)

To make an Altair figure, we need to do the following steps:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how you've split the explanation up into two modes -- let's do the same for Plotly?

Comment on lines +61 to +74
- title: JupyterChart update
description: "Shows how Shiny can access and update an Altair figure using the JupyterChart representation. This example builds on the previous basic example to show how Shiny can update the Altair figure reactively."
apps:
- title: Preview
file: app-variation-update-express.py
height: 720
- title: Express
file: app-variation-update-express.py
shinylive:
height: 720
- title: Core
file: app-variation-update-core.py
shinylive:
height: 720

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would bring the updating variations down below the "responding to user interaction" examples.

Updating (more precisely, mutating) charts in this way is more of a "only do this if you really need to for performance". Otherwise, you should just lean into the reactivity that render_altair provides

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants