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

How to make a custom panel responsive to selection #39

Open
RiboRings opened this issue May 1, 2024 · 2 comments
Open

How to make a custom panel responsive to selection #39

RiboRings opened this issue May 1, 2024 · 2 comments

Comments

@RiboRings
Copy link

Problem

Recently I was trying to make the panels of iSEEtree reactive to selections transmitted by other panels, like the RowDataTable. I was struggling because even after adding a .multiSelectionResponsive and .multiSelectionRestricted methods to the custom panel, they would not change upon selecting rows in RowDataTable. An example of this was reported in this iSEEtree issue.

Solution

After a while, I discovered that it would worked if I added the following selection to the .generateOutput method (taken from here):

  all_cmds[["select"]] <- .processMultiSelections(x, all_memory, all_contents, panel_env)

  if (is.null(panel_env[["row_selected"]])){
    panel_env[["se"]] <- se
  } else {
    panel_env[["se"]] <- se[unlist(panel_env[["row_selected"]]), ]
  }

Also, I wanted this specific panel (RowTreePlot) to be reactive only to row selection (and not column selection), so I added the following methods:

setMethod(".multiSelectionRestricted", "RowTreePlot", function(x) {
  slot(x, "RowSelectionRestrict")
})

setMethod(".multiSelectionResponsive", "RowTreePlot", function(x, dims = character(0)) {
  if ("row" %in% dims) {
    return(TRUE)
  }
  return(FALSE)
})

and hid the column-specific observers:

#' @importFrom methods callNextMethod
setMethod(".hideInterface", "RowTreePlot", function(x, field) {
  if (field %in% c("SelectionHistory", "ColumnSelectionRestrict",
                   "ColumnSelectionDynamicSource", "ColumnSelectionSource")) {
    TRUE
  } else {
    callNextMethod()
  }
})

The fixing commit is available here.

@kevinrue
Copy link
Member

kevinrue commented May 1, 2024

Regarding your first code block

  if (is.null(panel_env[["row_selected"]])){
    panel_env[["se"]] <- se
  } else {
    panel_env[["se"]] <- se[unlist(panel_env[["row_selected"]]), ]
  }

Any particular reason for the syntax is.null(panel_env[["row_selected"]]) ?

I couldn't recognise the coding pattern, so I went to check in iSEE/iSEE and found this:
https://github.com/iSEE/iSEE/blob/51cd280a4486e7a6173e0856bc8833e9c75f7a98/R/family_RowDotPlot.R#L450

        if (exists("row_selected", envir=envir, inherits=FALSE)) {
            target <- "row_selected"
        } else {
            target <- "list()"
        }

Is your row_selected expected to be NULL or can you simply check for its existence?

@RiboRings
Copy link
Author

Thank you! I wasn't aware of this cleaner solution. It will be added to the next version.

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

No branches or pull requests

2 participants