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

could not find function "treeToJSON" #97

Open
alezulu73 opened this issue May 7, 2020 · 9 comments
Open

could not find function "treeToJSON" #97

alezulu73 opened this issue May 7, 2020 · 9 comments

Comments

@alezulu73
Copy link

I'm using the shinyTree packages to make a tree from a existing data.frame. I made the tree with the function FromDataFrameTable:

xN <- FromDataFrameTable(temp, colLevels = list(NULL, c("floor","Tecno"),
c("")), na.rm = TRUE)

Later I use the function treeToJSON(xN, pretty = TRUE) to reder the tree.

The apps works well in my local instance of Rstudio, a windows machine. But when I upload the app to my shiny web server, the run application stop with an error "could not find function treeToJSON".

The shinytree version in both instances is ver 0.2.7.

@trafficonese
Copy link
Contributor

The CRAN version does not have the function treeToJSON yet. So you woul have to reinstall shinyTree on the server from github. Unfortunately the version number of both (CRAN and dev) is ‘0.2.7’, that might be a bit confusing.

@hugokoopmans
Copy link

hugokoopmans commented Apr 15, 2021

This is an issue for me, when can we expect and update to CRAN version @trafficonese
So this works on a server that uses CRAN packages?

please advise

@dkd58
Copy link

dkd58 commented Jan 20, 2022

What is the update on this issue, @trafficonese?
Will the CRAN version be updated in the near future?
And will the new version of treeTOJSON also take account of the warning message issued by data.tree: "Node$fields will be deprecated in the next release. Please use Node$attributes instead."? This would prevent a lot of unnecessary messages...
Thanks!

@trafficonese
Copy link
Contributor

I'm not maintainer of this package, so I can't tell you when a new version will be uploaded to CRAN. I think we should ask @bellma-lilly instead.

I also don't use the data.tree functionality and I'm not very familiar with that package. I think @JasperSch implemented that.

@bellma-lilly
Copy link
Contributor

@schaffman5

@maspotts
Copy link

maspotts commented Apr 9, 2022

I also can't find treeToJson, although I've installed from github (and unloaded the CRAN package's namespace first). Am I missing something?

NB: what I'm trying to do is transform a data.tree (Node) tree so I can pass it to jsTree() and thus create a static (jsQuery-enabled) HTML page with a collapsible version of my tree.

Any help gratefully appreciated!

@hugokoopmans
Copy link

any progress here,,,?

@JasperSch
Copy link
Contributor

JasperSch commented Aug 1, 2022

As far as I can tell it's just waiting on a CRAN release by the maintainer, which I believe is @schaffman5 .

As long as it is not released, installing from github should make it accessible:

remotes::install_github("https://github.com/shinyTree/shinyTree")

You could alternatively also copy code here https://github.com/shinyTree/shinyTree/blob/master/R/data.tree-conversion.R and include it in your own package.

In terms of the side questions about the internal workings of treeToJSON, I'm sorry to say I haven't contributed to that and I'm not very familiar with data.tree myself.

@nick-youngblut
Copy link

If you have a data.frame with parent & child columns, you can use the following code to produce a nested list for input to shinyTree:

#' Find roots in data.frame
findRoots = function(df){
  x = df[!df[,1] %in% df[,2], 1]
  x = unique(as.character(x))
  return(x)
}

#' Make a hierarchical list from a data.frame with 'parent' and 'child' columns
maketreelist = function(df, root = df[1, 1], rec_cnt = 0, max_rec = 10) {
  root = as.character(root)
  # initialize new sub-tree
  r = list()
  # checking recursion level
  rec_cnt = rec_cnt + 1
  if(rec_cnt > max_rec){
    return(r)
  }
  # children of root
  children = as.character(df[df[, 1] == root, 2])
  # recursive
  for(child in children){
    if(child %in% df[,1]){   # child is node
      r[[child]] = maketreelist(df, child, rec_cnt)
    } else {       # child is leaf 
      r[[child]] = child
    }
  }
  return(r)
}

#' Convert data.frame (2 column: parent --> child) to nested list
df2nestedList = function(df, parent_col=1, child_col=2){
  if(is.null(df)){
    return(NULL)
  }
  df = df[,c(parent_col, child_col)]
  L = list()
  for(r in findRoots(df)){
    L[[r]] = maketreelist(df, r)
  }
  return(L)
}

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

8 participants