Repository navigation
Support locator() and identify() in the Plots pane - #1486
Draft
juliasilge wants to merge 6 commits into
Draft
juliasilge wants to merge 6 commits into
juliasilge wants to merge 6 commits into
Conversation
…upt in `locator()`
juliasilge
added a commit
to posit-dev/positron
that referenced
this pull request
Nov 18, 2026
Also brings in posit-dev/ark#1484 and posit-dev/ark#1485. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
locator()doesn't work because we shadow apng()device positron#6704locator()andidentify()in the Plots pane positron#17405locator(),identify(), andgrid::grid.locator()now work in the Positron Plots pane. When R asks for a point, the Plots pane shows the plot with a crosshair cursor and a prompt. The user clicks the plot, and R gets the point in user coordinates, as with other on-screen devices. The Finish button, Esc, or an interrupt ends the call.Before this change, these functions did not work at all. The Ark device wraps the png or ragg device, and neither device has a usable
locatorcallback.How it works
The design is based on
file.choose(), which asks Positron for a file with a blocking frontend request on stdin. The graphics device now has alocatorcallback and for each click,DeviceContext::locate()does these steps:locator()call in the same request asplot()has a plot to click on.locate_plot_pointrequest on the UI comm with the plot comm ID and the image size, then it waits for the reply on stdin.The reply is the clicked point as fractions of the image (0 to 1, from the top left corner), or
nullwhen the user finishes. Ark changes the fractions to device coordinates with the device bounds. The image goes on IOPub and the request goes on stdin, so the request can arrive first. Positron accepts clicks only on a loaded image of the requested size.locator()returns at once, as if the user finished, in a notebook session, without a UI comm, when the pre-render fails, during a resize replay, or when an interrupt is pending.identify()draws its labels in graphical input mode, sohook_mode()detects them from the mode switch that R makes after each label. On an interrupt, the callback waits for the interrupt to be pending and then raises it once, so the rest of the expression does not run.Stale replies on stdin
Before this change, a late reply to an interrupted stdin request answered the next request. For example, after an interrupted
file.choose()orreadline(), a late reply became the answer to the nextreadline(). Amalthea now discards these replies:input_requestis a late reply, so Amalthea discards it.jupyter_client) send none.Positron sends each reply with the header of its request as the parent. The reply handling also uses
log_err()instead ofunwrap().Known limitations
locator(type = "p")draws, and labels thatidentify()draws, show only after the call returns. R adds the call to the display list when the call returns, and Ark renders from the display list.locator()does not stop the rest of the top-level input. For example, withlocator(1)on one line andcat("after")on the next line, an interrupt endslocator()and thencat("after")runs.readline()has the same behavior. To prevent this, put the code in braces:{ locator(1); cat("after") }.jupyter console),dev.capabilities("locator")isTRUE, butlocator()returnsNULLat once.Validation Steps
With the companion PR:
plot(1:10); locator(2).identify(1:10), click two points, and then click Finish. R prints the indices, and the labels show on the plot.Positron Release Notes
New Features
locator(),identify(), andgrid::grid.locator()now work in the Plots pane. Click the plot to choose a point (Plots: R:locator()doesn't work because we shadow apng()device positron#6704).Bug Fixes
readline()orfile.choose()no longer becomes the answer to the next prompt.