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

get_selected after treeToJSON not working #103

Open
Jorges1000 opened this issue Dec 2, 2020 · 2 comments
Open

get_selected after treeToJSON not working #103

Jorges1000 opened this issue Dec 2, 2020 · 2 comments

Comments

@Jorges1000
Copy link

I loaded the package example:

library(shiny)
library(shinyTree)
#' Define server logic required to generate a simple tree
#' @author Jeff Allen \email{jeff@@trestletech.com}
shinyServer(function(input, output, session) {

  output$tree123 <- renderTree({
    list(
      root1 = structure("123"),
      root2 = list(
        SubListA = list(leaf1 = "", leaf2 = "", leaf3=""),
        SubListB = list(leafA = "", leafB = "")
      )
    )
  })

  output$sel_names <- renderPrint({
    tree <- input$tree123
    req(tree)
    get_selected(tree)
  })
  output$sel_slices <- renderPrint({
    tree <- input$tree123
    req(tree)
    get_selected(tree, format = "slices")
  })
  output$sel_classid <- renderPrint({
    tree <- input$tree123
    req(tree)
    get_selected(tree, format = "classid")
  })
})

Works as described.

Then I run this minimal example:

library(data.table);library(data.tree)
library(shiny);library(shinyTree);library(shinyjs)
df <- data.table(pathString=c('./a/1/1','./a/1/2/1','./b/1','./b/2'),Attr=c(1,1,2,3))
n <- as.Node(df)
ui <- fluidPage(
  useShinyjs(),
  fluidRow(
    shinyTree("tree")
  ),
  fluidRow(verbatimTextOutput('Attr'))
)
#################################
server <- function(input, output) {
  get_json <- reactive({
    treeToJSON(n, pretty = TRUE)
  })
  output$tree <- renderTree(get_json())
  output$Attr <- renderPrint({
    tree <- input$tree
    req(tree)
    get_selected(tree)
  })
} # end server
shinyApp(ui = ui, server = server)`

The output is just and empty list(). Re-running the first app again afterwards also shows the same symptom.

image

sessionInfo:

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shinyjs_2.0.0     shinyTree_0.3.0   shiny_1.5.0       data.tree_1.0.0   data.table_1.13.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5        magrittr_2.0.1    xtable_1.8-4      R6_2.5.0          rlang_0.4.9       fastmap_1.0.1     stringr_1.4.0    
 [8] tools_4.0.3       withr_2.3.0       htmltools_0.5.0   yaml_2.2.1        digest_0.6.27     jsTree_1.0.1      zip_2.1.1        
[15] later_1.1.0.1     htmlwidgets_1.5.2 promises_1.1.1    rsconnect_0.8.16  mime_0.9          openxlsx_4.2.3    stringi_1.5.3    
[22] compiler_4.0.3    jsonlite_1.7.1    httpuv_1.5.4 
@bellma-lilly
Copy link
Contributor

I can't reproduce; your example works for me. Make sure you are using the github version of shinyTree.

@hugokoopmans
Copy link

apperently theres a difference in clicking the little triangle to open a sub tree (>> nothing selected still so empty) and actually clicking on a leave in the tree...

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

3 participants