Shiny, Sortable returning labels instead of index?

Hi all,
How do i retrieve the Values of the labels from a sortable bucket_list?
This chunk creates a dynamic number of lists in a module.

                   output$ClusterToGates <- renderUI({
                     rank_list_items <- lapply(1:input$NoOfBeads, function(i) {
                       #
                       #print(paste0(ns("Gate"),i))
                       sortable::add_rank_list(
                         text = paste0("Gate No: ", i),
                         labels = NULL,
                         input_id = paste0(ns("Gate"), i),
                         options = sortable::sortable_options(multiDrag = TRUE)
                       )
                     })
                     isolate(r$gates <- list())
                     isolate(for (id in 1:input$NoOfBeads) {
                       #print(id)
                       gateID <- paste0(ns("Gate"), id)
                       r$gates <- c(r$gates, paste0(ns("Gate"), id))
                     })
                     rank_list_Overview <-
                       list(
                         sortable::add_rank_list(
                           text = "Clusters to ignore",
                           labels = r$clusterInfos,
                           input_id = paste(ns("Overview")),
                           options = sortable::sortable_options(multiDrag = TRUE)
                         )
                       )
                     rank_list_Total <-
                       append(rank_list_Overview, rank_list_items)
                     do.call(
                       sortable::bucket_list,
                       args = c(
                         header = "Drop the Clusters in the corresponding Gate",
                         group_name = ns("GateBucketList"),
                         #options = sortable::sortable_options(multiDrag = TRUE),
                         rank_list_Total
                       )
                     )
                   })

when i try to retrieve the labels using
input$GateBucketList

I only get a list of indices not the actual value of the label.
How to i retrieve the values directly?

$`calibration_1-Overview`
[1] "1" "2"

$`calibration_1-Gate1`
[1] "4" "5" "3"

Hard to know whats going on with your code, because it is not reproducible.

Out of the box behaviour is to get label values not indices.
Are you sure your labels arent simply 1,2, 3 etc ?

library(sortable)
library(shiny)

ui <- fluidPage(
  bucket_list(
    header = "This is a bucket list. You can drag items between the lists.",
    add_rank_list(
      text = "Drag from here",
      labels = c("a", "bb", "ccc"),
      input_id = "l1"
    ),
    add_rank_list(
      text = "to here",
      labels = NULL,
      input_id = "l2"
    )
  )
)

server <- function(input, output, session) {
  observeEvent(input$l1,
               print(input$l1))
  observeEvent(input$l2,
               print(input$l2))
}

shinyApp(ui, server)
1 Like

Much appreciated!
Actually it turns out that my labels are a list with integers as names.

$`1`
                                        SampleName Cluster           NoOfDataPoints
1: A04 0ul High titer Plasma1.fcs || Cluster No :        0 || NoOfDataPoints : 1933

$`2`
                                        SampleName Cluster            NoOfDataPoints
1: A04 0ul High titer Plasma1.fcs || Cluster No :        1 || NoOfDataPoints : 23067

The labels got shown in the ui perfectly but on the backendsite i would get numbers back. Super strange.
Thank you for the help!!

Reproducible dynamic bucket_list of rank_lists:

library(sortable)
library(shiny)

ui <- fluidPage(
  verbatimTextOutput("text"),
  uiOutput("BucketList")
  )

server <- function(input, output, session) {
    output$BucketList <- renderUI({
      
      rank_list_items <- lapply(1:3, function(i) {
        sortable::add_rank_list(
          text = paste0("List-: ", i),
          labels = NULL,
          input_id = paste0("List-", i),
          options = sortable::sortable_options(multiDrag = TRUE)
        )
      })
      
      rank_list_Overview <-
        list(
          sortable::add_rank_list(
            text = "Starting List",
            labels = c("a", "bb", "ccc"),
            input_id = "Overview"
          ),
          options = sortable::sortable_options(multiDrag = TRUE)
        )
      rank_list_Total <-
      append(rank_list_Overview, rank_list_items)
    
    do.call(
      sortable::bucket_list,
      args = c(header = "Drop the Clusters in the corresponding Gate",
               group_name = "bucketList",
               rank_list_Total)
    )
    
    
    })
    observe(
    output$text <- renderPrint(input$bucketList))
}

shinyApp(ui, server)

what you shared here seems fine, only uiOutput(ns("BucketList")) doesn't need the ns() , and would error in this context as it would be undefined

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.