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

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

Closed
averissimo opened this issue Aug 4, 2023 · 3 comments · Fixed by #332
Closed

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

averissimo opened this issue Aug 4, 2023 · 3 comments · Fixed by #332
Assignees
Labels
core enhancement New feature or request

Comments

@averissimo
Copy link
Contributor

averissimo commented Aug 4, 2023

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

  • Use shinyjs::disable/enable when there are no choices
  • Use shinyWidgets::virtualSelectInput (already a dependency) that has a disabled parameter

Proof of concept

Click to expand possible patch
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 averissimo added the enhancement New feature or request label Aug 4, 2023
@averissimo averissimo assigned averissimo and unassigned averissimo Aug 7, 2023
@averissimo averissimo added the core label Aug 7, 2023
@averissimo averissimo removed their assignment Aug 8, 2023
@averissimo
Copy link
Contributor Author

averissimo commented Sep 8, 2023

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

image

@danielinteractive
Copy link
Collaborator

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

@averissimo
Copy link
Contributor Author

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

averissimo added a commit that referenced this issue Sep 12, 2023
# Pull Request

Fixes #324

### Possible simplification:

Use of `shinyjs::enable()`/`shinyjs::disable()` would remove the custom
message handler with the caveat of adding a dependency to the package.

### Changes description

* Use of `selectizeInput` instead of `selectizeInput`
* Adds placeholder to `adtteSpecInput`, `assaySpecInput` & `geneSpec`
  * Harcoded string: `- Nothing selected -`
* Uses JS to disable / enable the dropdown
* note: the message handler can be run multiple times, but it will only
re-define the function per [Shiny
documentation](https://github.com/rstudio/shiny/blob/eddc3047d4e1fd500bdb128f5c02109afa12d948/srcts/src/shiny/shinyapp.ts#L86C17-L86C73)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants