Using the code below, I could create a very nice list of choices. I would like to add a "select all" choice right above the first choice (Ohio). Is there any easy fix for this?
Thanks,
Nader
collapsibleCheckboxGroupInput(
inputId = "county_", "Select County:", i = 5, selected = "Ohio",
choices = c("Ohio", sort(unique((map_Ohio$County[map_Ohio$County !="Ohio"]))))),
collapsibleCheckboxGroupInput <-
function(inputId, label, i, choices = NULL, selected = NULL, width = NULL,
choiceNames = NULL, choiceValues = NULL){
input <- checkboxGroupInput(inputId, label, choices = choices,
selected = selected, width = width,
choiceNames = choiceNames,
choiceValues = choiceValues)
checkboxes <- input[[3]][[2]][[3]][[1]]
id_btn <- paste0(inputId, "_btn")
id_div <- paste0(inputId, "_collapsible")
btn <- actionButton(id_btn, "More...",
icon = icon("collapse-up", lib = "glyphicon"),
class = "btn-primary btn-sm",
`data-toggle`="collapse",
`data-target` = paste0("#", id_div))
collapsible <- div(id = id_div, class = "collapse")
collapsible$children <- checkboxes[(i+1):length(checkboxes)]
children <- c(checkboxes[1:i], list(btn), list(collapsible))
input[[3]][[2]][[3]][[1]] <- children
script <- sprintf('$(document).ready(function(){
$("#%s_collapsible").on("hide.bs.collapse", function(){
$("#%s_btn").html("<span class=\\\"glyphicon glyphicon-collapse-down\\\"></span> More...");
});
$("#%s_collapsible").on("show.bs.collapse", function(){
$("#%s_btn").html("<span class=\\\"glyphicon glyphicon-collapse-up\\\"></span> Less...");
});
});', inputId, inputId, inputId, inputId)
tagList(input, tags$script(HTML(script)))
}
Aucun commentaire:
Enregistrer un commentaire