Skip to content

Commit

Permalink
Fixed rename_node event handler. Close #25.
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Dec 16, 2023
1 parent d393f5d commit 669d6f3
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
87 changes: 87 additions & 0 deletions inst/essais/on_rename.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
library(jsTreeR)
library(shiny)
library(jsonlite)

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

ui <- fluidPage(jstreeOutput("mytree"), verbatimTextOutput("mytree_full"))

server <- function(input, output, session) {
output[["mytree"]] <- renderJstree({
jstree(nodes, contextMenu = TRUE, checkboxes = TRUE, checkWithText = FALSE)
})

output$mytree_full <- renderPrint({toJSON(input$mytree_full, pretty = TRUE)})
}



shinyApp(ui, server)
2 changes: 1 addition & 1 deletion inst/htmlwidgets/jstreer.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ HTMLWidgets.widget({
$el.on("rename_node.jstree", function(e, data) {
if(inShiny) {
var instance = data.instance;
var parentPath = instance.get_path(data.node.parent);
var parentPath = instance.get_path(data.node.parent) || [];
var oldPath = parentPath.concat(data.old);
var newPath = parentPath.concat(data.text);
Shiny.setInputValue("jsTreeRenamed:jsTreeR.move", {
Expand Down

0 comments on commit 669d6f3

Please sign in to comment.