insightsengineering / teal.modules.hermes

RNA-seq analysis modules to add to a teal application
https://insightsengineering.github.io/teal.modules.hermes/
Other
7 stars 1 forks source link

[Feature Request]: Disable select input when there are no choices #324

Closed averissimo closed 1 year ago

averissimo commented 1 year ago

Feature description

The select inputs from assaySpec would improve from being disabled with a placeholder when they have no choices.

For example on the Barplot (or KM module) of the RNA-Seq app app it has a weird behaviour when trying click on the dropdown (see below).

There are some options to implement this

Proof of concept

Click to expand possible patch ```R diff --git a/R/assaySpec.R b/R/assaySpec.R index 55d4c7a..f36efdf 100644 --- a/R/assaySpec.R +++ b/R/assaySpec.R @@ -19,7 +19,7 @@ assaySpecInput <- function(inputId, # nolint selectInput( inputId = ns("name"), label = label_assays, - choices = "" + choices = character(0) ) } @@ -119,6 +119,9 @@ assaySpecServer <- function(id, # nolint hermes::h_short_list(removed_assays), "as per app specifications" )) } + if (length(remaining_assays) == 0) { + remaining_assays <- list("No assays available" = "") + } remaining_assays }) @@ -129,12 +132,17 @@ assaySpecServer <- function(id, # nolint "name", choices = choices ) + if (length(choices) > 0 && choices[[1]] != "") { + shinyjs::enable("name") + } else { + shinyjs::disable("name") + } }) reactive({ choices <- choices() validate(need( - length(choices) > 0, + length(choices) > 0 && choices[[1]] != "", "No assays eligible for this experiment, please make sure to add normalized assays" )) input$name ```

image

Screencast of issue

Screencast from 2023-08-04 12-54-03.webm

averissimo commented 1 year ago

I created a POC on branch 324_disable-empty-select-encoding@main

image

danielinteractive commented 1 year ago

Thanks @averissimo , can you make a PR for this since you have the POC branch already? thanks

averissimo commented 1 year ago

Created here

@danielinteractive there's a possible simplification that doesn't need any custom message, but adds a dependency to the package.

Please keep that in mind when reviewing the PR