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

input[["mytree_full"]] is not updated on expanding a node #16

Closed
ismirsehregal opened this issue Oct 9, 2023 · 4 comments
Closed

input[["mytree_full"]] is not updated on expanding a node #16

ismirsehregal opened this issue Oct 9, 2023 · 4 comments

Comments

@ismirsehregal
Copy link

ismirsehregal commented Oct 9, 2023

I'd like to save the state of a jstree, so the user has the possibility to come back later and continue to work on it.

Currently the full input state (e.g. input[["mytree_full"]]) is not updated on expanding a node. However, it is updated when adding a child node via the contextMenu:

library(jsTreeR)
library(shiny)

ui <- fluidPage(
  textInput("test", "test"),
  jstreeOutput("mytree"),
  textOutput("opened")
)

server <- function(input, output, session){
  output[["mytree"]] <- renderJstree({
    # jstreeDestroy(session, id = "mytree")
    nodes <- list(
      list(
        text = paste0(input$test, "Branch 1"),
        state = list(opened = TRUE, disabled = FALSE),
        type = "parent",
        children = list(
          list(text = "Leaf A", type = "child"),
          list(text = "Leaf B", type = "child"),
          list(text = "Leaf C", type = "child"),
          list(text = "Leaf D", type = "child")
        )
      ),
      list(text = "Branch 2", type = "parent", state = list(opened = TRUE))
    )
    jstree(nodes, contextMenu = TRUE)
  })
  
  output$opened <- renderText({
    if(isTruthy(input[["mytree_full"]])){
      paste("Is node 1 opened?:", input[["mytree_full"]][[1]]$state$opened)
    }
  })
}  

shinyApp(ui, server)

screen

@stla
Copy link
Owner

stla commented Oct 9, 2023

Hmm I didn't deal with this package for a while, it will be hard to fix. And maybe it's a bug from the JS library.

@stla
Copy link
Owner

stla commented Oct 9, 2023

I've upgrader the JS library but nothing changes. In fact, it seems that the input[["mytree_full]] doesn't react at all.

@stla
Copy link
Owner

stla commented Oct 9, 2023

Ok it works now, I had to add some events.

Could you try remotes::install_github("stla/jsTreeR@v3.3.16?

@ismirsehregal
Copy link
Author

Thanks for the swift investigation Stéphane, works perfectly!

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

2 participants