Skip to content

How to make a custom panel responsive to selection #39

Open

Description

@RiboRings

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.

Activity

  1. kevinrue commented on May 1, 2024

    @kevinrue
    Member

    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?

  2. RiboRings commented on May 1, 2024

    @RiboRings
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions