Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand/Collapse buttons at the top of the tree #42

Open
mangupedia opened this issue Oct 8, 2018 · 2 comments
Open

Expand/Collapse buttons at the top of the tree #42

mangupedia opened this issue Oct 8, 2018 · 2 comments

Comments

@mangupedia
Copy link

Brilliant work on the fork ! Thanks a lot.

https://github.com/metrumresearchgroup/jsTree
Expand/Collapse buttons are offered by jsTree package. Do we have something similar on this?

Or can we configure that using javascript and action buttons to Expand/Collapse nodes for the full tree or may be till some specific node level?

@bellma-lilly
Copy link
Contributor

You can implement this with an action button. When the action button is pressed, set the stopened attribute for each node (attr(output_tree, "stopened") <- TRUE) and update the tree.

javascript would be faster, but it is not implemented in shinyTree

@YsoSirius
Copy link
Contributor

YsoSirius commented Oct 20, 2018

Or you run the JS code with shinyjs and some actionButtons.


library(shiny)
library(shinyTree)
library(shinyjs)

ui <- {fluidPage(
  useShinyjs(),
  actionButton("closeAll", "Close Tree"),
  actionButton("openAll", "Open Tree"),
  shinyTree("tree")
)}

server <- function(input, output, session) {
  output$tree <- renderTree({
    list(
      root1 = list(
        SubListA = list(leaf1 = "", leaf2 = "", leaf3=""),
        SubListAB = list(leaf1 = "", leaf2 = "", leaf3=""),
        SubListAC = list(leaf1 = "", leaf2 = "", leaf3="")
      ),
      root2 = list(
        SubListB = list(leaf1 = "", leaf2 = "", leaf3=""),
        SubListBA = list(leaf1 = "", leaf2 = "", leaf3=""),
        SubListBC = list(leafA = "", leafB = "")
      )
    )
  })
  observeEvent(input$closeAll, {
    runjs(HTML('$("#tree").jstree("close_all");'))
  })
  observeEvent(input$openAll, {
    runjs(HTML('$("#tree").jstree("open_all");'))
  })
}

shinyApp(ui,server)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants