Replaces the contents of a shinyTree with a new tree, for
example from an observer. Like the tree renderTree sends, the
new one is reported in input$tree once it has loaded – unless it is
the tree input$tree already holds, so an observer of
input$tree that sends the tree back does not loop.
Arguments
- session
The current session variable.
- treeId
The identifier for the shinyTree object
- data
The new tree: a named nested list, as for
renderTree, or JSON in jsTree's format, as fromtreeToJSON.NULLleaves the tree as it is.
Details
A tree rendered with renderTree(lazy = TRUE) cannot be updated this
way, and updateTree stops with an error: change what its render
expression returns instead. If the tree has not been shown yet – it is in
a tab that has not been opened – the update is applied when it is.
Examples
if (interactive()) {
library(shiny)
ui <- fluidPage(actionButton("reset", "Reset"), shinyTree("tree"))
server <- function(input, output, session) {
output$tree <- renderTree(list(a = list(b = ""), c = ""))
observeEvent(input$reset, {
updateTree(session, "tree", list(root = list(leaf = "")))
})
}
shinyApp(ui, server)
}