Skip to content

Size plots appropriately in R notebooks and Quarto inline output#12539

Merged
jmcphers merged 15 commits intomainfrom
feature/quarto-cell-execution-metadata
Mar 20, 2026
Merged

Size plots appropriately in R notebooks and Quarto inline output#12539
jmcphers merged 15 commits intomainfrom
feature/quarto-cell-execution-metadata

Conversation

@jmcphers
Copy link
Copy Markdown
Collaborator

@jmcphers jmcphers commented Mar 17, 2026

This change adds metadata to execution requests so that it is possible for kernels to size plots to fit the viewport/DPI.

For Quarto, we add cell options (such as fig-width and fig-height) to the execution metadata; for both Quarto inline outputs and Jupyter editors, we add the width of the output field and the device pixel ratio to the execution request.

In notebooks, this means that your plots render crisply on Retina displays and are sized appropriately to your viewport:

image

In Quarto inline outputs, this means that figure width/height are respected, too, so you get a preview with the correct aspect ratio:

image

Requires posit-dev/ark#1119
Requires posit-dev/qa-example-content#116
Related to quarto-dev/quarto#938

Addresses #8104
Addresses #12150

Release Notes

New Features

Bug Fixes

QA Notes

This PR doesn't attempt to size Python plots, though it takes the first step towards doing so by adding the right metadata. I added a hidden magic you can use to see what is being sent to Python:

%_positron_exec_metadata

The Ark equivalent is .ps.internal(active_request()).

It also doesn't apply to the Plots pane, just notebook-style execution. We'll need to wait for a new Quarto extension to do that (quarto-dev/quarto#938).

Test tags: @:quarto @positron-notebooks @notebooks

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 17, 2026

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:quarto

readme  valid tags

@jmcphers jmcphers requested a review from nstrayer March 17, 2026 00:34
nstrayer
nstrayer previously approved these changes Mar 19, 2026
Copy link
Copy Markdown
Contributor

@nstrayer nstrayer left a comment

Choose a reason for hiding this comment

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

This is a huge QOL improvement! Thank you!

Just a couple code questions but nothing blocking at all!

* Returns dimensions used by the kernel to size outputs (e.g. plot
* rendering). Uses the same formula as QuartoOutputViewZone._getWidth().
*/
private _getEditorLayoutMetadata(): Record<string, unknown> | undefined {
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.

Is this a general Record<string, unknown> type so that it catches problems when future metadata is added? In which case I wonder if using satisfies Record<string, unknown> on the return would help while letting you keep nice return types for using the method?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

A good point. After reviewing this I think the best change is to use a type for this layout metadata and then spread it right before we send it to the kernel! That's done here: fee654a

};
}

// Fall back to Positron notebook instances.
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 wonder if we should build this into the notebook editor interface to help get rid of some of these implementation details.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it does feel weird to reach into the editor's DOM for these values. I've moved this to the editor itself: efe746e

@jmcphers jmcphers merged commit 35d4a17 into main Mar 20, 2026
62 checks passed
@jmcphers jmcphers deleted the feature/quarto-cell-execution-metadata branch March 20, 2026 16:08
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants