Skip to content

Update treeNavigatorServer #36

Open
@CFeregrino

Description

@CFeregrino

Hello, I might be asking an ignorant question, but I am not extremely familiar with jsTrees.

I am trying to generate a different tree everytime a folder is selected within a dynamic list of folders. For this, I am using treeNavigatorServer. But I cannot update the tree that's generated whenever my reactive value is updated. I don't know if I should be using jstreeUpdate, since treeNavigatorServer does not output nodes, but Paths. Below is the server part of the code I'm trying to make work.

Thank you for the great package!

shinyServer(function(input, output, session){
# Here I am looking for all the folders that contain sc*seq. These become buttons, which will update my.folder() when clicked
my.buttons = system("find ./ -maxdepth 2 -name 'sc*seq' -type d",
                      intern = T)
  my.buttons.lab = gsub("_|/"," ",sub(".*DATA/","",my.buttons))
output$dynamic_buttons =  renderUI({

    lapply(as.list(1:length(my.buttons.lab)), function(laboo){

      actionButton(inputId = paste0("btn_",laboo), my.buttons.lab[laboo])
    })
  })

  my.folder = reactiveVal("")

  observe({
    #go throgh the buttons
    for (laboo in 1:length(my.buttons.lab)) {
      btn_id = paste0("btn_",laboo)
      #has the button been clicked?
      if(!is.null(input[[btn_id]]) && input[[btn_id]] > 0) {
        #If it has been clicked most recently,get it.
        isolate({
          if(input[[btn_id]] == max(sapply(1:length(my.buttons.lab),
                                           function(laboo) input[[paste0("btn_",laboo)]]))){
            my.folder(my.buttons[laboo])
          }
        })
      }
    }
  })

  output$selected_output = renderText({ paste("You clicked:", my.folder())})

  Paths <- treeNavigatorServer(
    "explorer", rootFolder = my.folder(),
    search = list( # (search in the visited folders only)
      show_only_matches  = TRUE,
      case_sensitive     = TRUE,
      search_leaves_only = TRUE
    ),
    contextMenu = list(items = menuItems, select_node = FALSE),
    pattern = "\\.txt$|\\.gz$",
  )
})

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