Skip to content

changed.jstree event is not captured #34

Description

@stewerner

I was trying to implement a button to select / deselect all nodes. However, it seems this change is not reflected in the shiny input:

screen

Example:

library(jsTreeR)
library(shiny)
library(shinyjs)
library(jsonlite)

nodes <- list(
  list(
    text = "Branch 1",
    state = list(
      opened = TRUE,
      disabled = FALSE
    ),
    type = "parent",
    children = list(
      list(
        text = "Leaf A",
        state = list(
          opened = TRUE,
          disabled = FALSE,
          selected = FALSE
        ),
        type = "child"
      ),
      list(
        text = "Leaf B",
        state = list(
          opened = TRUE,
          disabled = FALSE,
          selected = FALSE
        ),
        type = "child"
      ),
      list(
        text = "Leaf C",
        state = list(
          opened = TRUE,
          disabled = FALSE,
          selected = FALSE
        ),
        type = "child"
      ),
      list(
        text = "Leaf D",
        state = list(
          opened = TRUE,
          disabled = FALSE,
          selected = FALSE
        ),
        type = "child"
      )
    )
  ),
  list(
    text = "Branch 2",
    type = "parent",
    state = list(
      opened = TRUE,
      disabled = FALSE,
      selected = FALSE
    )
  )
)

ui <- fluidPage(
  useShinyjs(),
  jstreeOutput("mytree"), 
  actionButton("select_all_nodes", "Select all"),
  actionButton("deselect_all_nodes", "Deselect all"),
  verbatimTextOutput("mytree_full")
)

server <- function(input, output, session) {
  output[["mytree"]] <- renderJstree({
    jstree(nodes, contextMenu = TRUE, checkboxes = TRUE)
  })
  
  observeEvent(input$select_all_nodes, {
    runjs("$('#mytree').jstree('select_all', false);")
  })
  
  observeEvent(input$deselect_all_nodes, {
    runjs("$('#mytree').jstree('deselect_all', false);")
  })
  
  output$mytree_full <- renderPrint({toJSON(input$mytree_full, pretty = TRUE)})
}

shinyApp(ui, server)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions