I am using the R package sortable
in a Shiny App in a similar way as described in this SO post, with the aim of drag-and-dropping values from one “source” rank_list
to a “destination” rank_list
.
I am facing the following issue : when the app starts, I would like the “destination” rank_list
to be already filled with one of the value of the “source” rank_list
. This means for the example here below that when the app starts the “Destination” box on the right already contains e.g. the “b” value.
Is it possible to achieve this ? How ? I guess there is probably a js solution, but I am really a newbie…
Thanks in advance for any help
library(shiny)
library(sortable)
ui <- fluidPage(
fluidRow(
column(
width = 6,
uiOutput("main_rank")
),
column( width =6,
rank_list(
text = "Destination",
labels = c(),
input_id = "other_rank",
options = sortable_options(group = "my_shared_group"))
)
)
)
server <- function(input,output) {
# Fixed Items as reactive
rankvars = reactive({
# Fixed Items
fixedItems = c("a", "b", "c", "d")
# used
used = c()
used = c(unique(input$other_rank))
# refill the list with unique items
unique(c(setdiff(fixedItems, used),used))
})
# Make the main rank as a reactive object
output$main_rank = renderUI({
fluidRow(
rank_list(
text = "Source",
labels = rankvars(), #colnames(Memory$data), #sample(paste0("list item ", 1:5)),
input_id = "main_list",
# be sure to have the same group name
options = sortable_options(group = "my_shared_group")
)
)
})
}
shinyApp(ui, server)