Opens or closes every node of a shinyTree in the browser,
for example from "Expand all" and "Collapse all" buttons. The tree's
contents are not resent, so selection, checkboxes and search are kept, and
input$tree reports each node's new open state as it would after a
user click.
Details
To control which nodes start open instead, set stopened = TRUE on
them when rendering the tree.
expandTree cannot be used on a tree rendered with
renderTree(lazy = TRUE), since it would have to fetch the whole
tree, and stops with an error. collapseTree works on any tree.
Examples
if (interactive()) {
library(shiny)
ui <- fluidPage(
actionButton("expand", "Expand all"),
actionButton("collapse", "Collapse all"),
shinyTree("tree")
)
server <- function(input, output, session) {
output$tree <- renderTree(list(a = list(b = list(c = ""))))
observeEvent(input$expand, expandTree(session, "tree"))
observeEvent(input$collapse, collapseTree(session, "tree"))
}
shinyApp(ui, server)
}