Description Usage Arguments Examples
Update the selected nodes of a checkbox tree.
1 | updateCheckboxTreeInput(session, inputId, checked)
|
session |
the Shiny |
inputId |
the id of the checkbox tree to update |
checked |
a list of selected nodes identified by their value |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | if(interactive()) {
library(shiny)
library(shinyCheckboxTree)
treedata <- list(
list(
value = "A",
label = "Node A",
title = "Hello, I am node A",
children = list(
list(
value = "Aa",
label = "Subnode Aa",
title = "I'm node Aa, a child of node A"
),
list(
value = "Ab",
label = "Subnode Ab",
title = "I'm node Ab, you can't select me since I have no checkbox",
showCheckbox = FALSE,
children = list(
list(
value = "Ab1",
label = "Subsubnode Ab1",
title = "I'm node Ab1, a child of node Ab, and I have no child"
),
list(
value = "Ab2",
label = "Subsubnode Ab2",
title = "I'm node Ab2, I'm red thanks to my CSS class",
className = "redNode"
)
)
)
)
),
list(
value = "B",
label = "Node B",
title = "I am node B, I am disabled (so my child is disabled as well)",
disabled = TRUE,
children = list(
list(
value = "Ba",
label = "Subnode Ba",
title = "I'm disabled but you can select me with the 'Update' button"
)
)
)
)
ui <- fluidPage(
tags$head(
tags$style(HTML(".redNode { color: red; }"))
),
br(),
fluidRow(
column(
width = 6,
checkboxTreeInput("tree", nodes = treedata, checked = list("Ab1"),
showExpandAll = TRUE)
),
column(
width = 6,
tags$fieldset(
tags$legend("Selected leaves:"),
verbatimTextOutput("checkedLeaves")
)
)
),
br(),
actionButton("update", "Update checkbox tree", class = "btn-warning")
)
server <- function(input, output, session) {
output[["checkedLeaves"]] <- renderPrint({
input[["tree"]]
})
observeEvent(input[["update"]], {
updateCheckboxTreeInput(session, "tree",
checked = list("Aa", "Ab2", "Ba"))
})
}
shinyApp(ui, server)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.