The following code consists of two containers or divs or bucket_lists from the sortable
R package and each bucket_list
consists of two add_rank_list
functions.
The first container elements are completly unmovable where the disabled
arguments in each add_rank_list
are set to TRUE
, while the second container allows the user to drag and drop the items except the first item, since the disabled
argument in the first add_rank_list
function is set to TRUE
but in the second function is set to FALSE
.
I would like to apply a red background color to the element in the second container if its value is "Camp". Additionally, I would like to apply the same background color to the element in the first container that shares the same row with the "Camp" element. Despite attempting different methods, I have been unable to achieve this outcome. Any assistance would be greatly appreciated.
library(shiny)
library(sortable)
ui <- fluidPage(
actionButton(inputId = "id1", "run"),
uiOutput("id2")
)
server <- function(input, output, session) {
observeEvent(input$id1, {
output$id2 <- renderUI({
tagList(
tags$style(
HTML(paste0("
.custom-sortable .rank-list-item-Camp {
background-color: red
}
"))
),
tags$script(
HTML("
$(document).ready(function() {
$('.custom-sortable .rank-list-item').each(function(index) {
if ($(this).text() === 'Camp') {
targetIndex = index;
}
});
$('.custom-sortable .rank-list-item').eq(targetIndex).addClass('rank-list-item-Camp');
});
")
),
div(
style = "width: 15%; float: left; overflow: hidden;",
bucket_list(
header = NULL,
class = c("default-sortable","custom-sortable" ),
orientation = c("vertical"),
add_rank_list(
text = NULL,
labels = 100,
options = sortable_options(disabled = T)
),
add_rank_list(
text = NULL,
labels = c(50,40,30,15),
options = sortable_options(disabled = T)
)
)
),
div(
style = "width: 15%; float: left; overflow: hidden;",
bucket_list(
header = NULL,
class = c("default-sortable", "custom-sortable"),
orientation = c("vertical"),
add_rank_list(
text = NULL,
labels = c("Fixed"),
options = sortable_options(disabled = T)
),
add_rank_list(
text = NULL,
labels = c("Camp", rep("No Info",3)),
options = sortable_options(disabled = F)
)
)
)
)
})
}
)
}
shinyApp(ui, server)