Skip to content

feat(data viewer): Allow reusing data viewer instead of opening a new…#1707

Merged
renkun-ken merged 2 commits into
REditorSupport:masterfrom
Fred-Wu:fix/reuse-dataview-panels
May 12, 2026
Merged

feat(data viewer): Allow reusing data viewer instead of opening a new…#1707
renkun-ken merged 2 commits into
REditorSupport:masterfrom
Fred-Wu:fix/reuse-dataview-panels

Conversation

@Fred-Wu
Copy link
Copy Markdown
Contributor

@Fred-Wu Fred-Wu commented May 12, 2026

This PR makes the data viewer to reused the viewer panels by view_id so repeated View() calls for the same data name refresh the existing viewer instead of opening a new one.

The sess side now reuses the same generated view_id for the same title while replacing the stored data state. The vscode side tracks open viewers by view_id, reveals the existing panel, restores the (rows: n) title, and reloads the webview so updated data is fetched.

Copy link
Copy Markdown

Copilot AI left a comment

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 updates the VS Code R data viewer workflow so repeated View() calls for the same data title reuse an existing viewer panel (via a stable view_id) and refresh its contents, instead of opening a new panel each time.

Changes:

  • VS Code: Track dynamic data viewer webview panels by view_id, reveal an existing panel when possible, and reload the webview content to fetch updated data.
  • sess (R): Introduce a per-session dataview_registry to reuse the same generated view_id for the same View() title, and allow dataview_register() to accept an explicit view_id.
  • sess (R) → VS Code: Include total_rows in the dataview notification so the panel title can be restored to the (rows: n) format when reusing.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/session.ts Reuse dynamic data viewer panels by view_id, reveal existing panels, and reload webview HTML to refresh data/title.
sess/R/server.R Initialize a session-level dataview_registry environment for stable view_id reuse.
sess/R/hooks.R Reuse view_id per View() title and include total_rows in dataview notifications.
sess/R/handlers.R Add dataview_new_id() and allow dataview_register(data, view_id=...) to overwrite/update existing state.

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

Comment thread sess/R/handlers.R
Comment on lines +265 to +271
repeat {
ts <- gsub("[^0-9]", "", format(Sys.time(), "%Y%m%d%H%M%OS6"), perl = TRUE)
view_id <- sprintf("dv_%s_%06d", ts, sample.int(999999L, 1L))
if (is.null(.sess_env$dataviews) || is.null(.sess_env$dataviews[[view_id]])) {
return(view_id)
}
}
Comment thread sess/R/handlers.R
Comment on lines +274 to 285
dataview_register <- function(data, view_id = NULL) {
if (is.null(.sess_env$dataviews)) {
.sess_env$dataviews <- list()
}
ts <- gsub("[^0-9]", "", format(Sys.time(), "%Y%m%d%H%M%OS6"), perl = TRUE)
view_id <- sprintf("dv_%s_%06d", ts, sample.int(999999L, 1L))

if (is.null(view_id)) {
view_id <- dataview_new_id()
}

state <- dataview_to_state(data)
.sess_env$dataviews[[view_id]] <- state
list(
@renkun-ken renkun-ken merged commit 20f32fe into REditorSupport:master May 12, 2026
8 of 10 checks passed
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