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

jstreeDestroy updates in shiny #11

Closed
RightChain opened this issue Oct 20, 2022 · 2 comments
Closed

jstreeDestroy updates in shiny #11

RightChain opened this issue Oct 20, 2022 · 2 comments

Comments

@RightChain
Copy link

I've run into an issue where I am feeding a reactive node list into the renderjstree function inside of a module, and the jstree does not update properly when the reactive updates. To get around this, a previous issue recommended using the jstreeDestroy function before updating the jstree data structure. I was able to update the jstree by doing this, but the search bar does not get destroyed.

3 things stood out to me while investigating this:

  1. The search bar is not properly destroyed by the jstreeDestroy function. (issue)
  2. Shouldn't jstreeDestroy be automatically called on any re-renders? (feature request)
  3. Note that for modular shiny functions, the jstreeDestroy function does not properly handle the different namespaces. (issue or feature request)

This is my minimal example below:

library(shiny)
library(jsTreeR)

#Module with jstree
jstreeUI <- function(id) {
  ns <- NS(id)
  jstreeOutput(ns('tree'))
}


jstreeServer <- function(input,output,session,nodes=reactive(NULL)) {
  output$tree <- renderJstree({
    #Destroy the tree each time
    jstreeDestroy(session, session$ns('tree'))

    #Call the tree
    jsTreeR::jstree(
      nodes = nodes(),
      search = TRUE,
      multiple = FALSE,
      theme = "proton")
  })
}


#Main ui and server functions
mainUI <- fluidPage(
  checkboxInput('list1','A',value=T),
  jstreeUI('a')
)


mainServer <- function(input,output, session) {
  #Update the data structure when the checkbox changes
  nodes <- reactive({
    if (input$list1) {
      return(list(list(text = "AAAAAAA")))
    } else {
      return(list(list(text = "BBBBBBB")))
    }
  })

  #Call module with jstree
  callModule(module=jstreeServer, id='a', nodes=nodes)
}

#Run shiny app
shinyApp(ui = mainUI, server = mainServer)

@stla stla closed this as completed in 3afed8a Oct 20, 2022
@stla
Copy link
Owner

stla commented Oct 20, 2022

Thanks for the report and the neat example!

  1. is fixed now. For 2) and 3), I don't know how to do.

@RightChain
Copy link
Author

Thank you!

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