Open
Description
I was trying to implement a button to select / deselect all nodes. However, it seems this change is not reflected in the shiny input:
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)
Metadata
Metadata
Assignees
Labels
No labels