AdeelK93 / collapsibleTree

Create Interactive Collapsible Tree Diagrams in R using D3.js
https://adeelk93.github.io/collapsibleTree/
158 stars 41 forks source link

Error in unclass(x) : cannot unclass an environment #24

Closed violetzh closed 6 years ago

violetzh commented 6 years ago

Hi AdeelK93!

First, this is a great package and very useful to visualize hierarchical data.

I have run into an issue when trying to generate a collapsible tree using the method collapsibleTreeNetwork, with strings (some quite long) as the attribute for each node. The error is: Error in unclass(x) : cannot unclass an environment If no attribute is assigned, then the tree will render with no error. Google tells me this could be a layout issue, but I am not exactly sure what it means. Would it be possible to provide some insights how to fix this?

The network data frame has 634 unique nodes. Here is my script:

library(shiny)
library(collapsibleTree)
library(data.tree)

aft_tree<-read.delim("aftv212_child_parent_class_tree_fixes.tsv", stringsAsFactors = F)
#convert a data.frame in network structure to a data.tree structure
aft_tree_network<-FromDataFrameNetwork(aft_tree)

#see if all node names are unique
print(AreNamesUnique(aft_tree_network))
#convert data.tree structure back to the data.frame in network structure with column names "from" and "to" 
#order of the nodes are preserved using this method
aft_tree_df<-ToDataFrameNetwork(aft_tree_network)

aft_tree_df_for_d3<-rbind(data.frame(from=NA, to="entity", stringsAsFactors = F),aft_tree_df)
aft_tree<-rbind(data.frame(parentLabel=NA, childLabel="entity", parentURI="", childURI="<http://purl.obolibrary.org/obo/BFO_0000001>", description="An entity is anything that exists or has existed or will exist. (axiom label in BFO2 Reference: [001-001])", root="<http://purl.obolibrary.org/obo/BFO_0000001>", depth=0, stringsAsFactors = F), aft_tree)
colnames(aft_tree)<-c("from", "to", "fromIRI", "toIRI", "description", "root", "depth")
aft_tree_for_d3_wDes<-cbind(aft_tree_df_for_d3, data.frame(aft_tree$description, stringsAsFactors = F))
colnames(aft_tree_for_d3_wDes)<-c("from", "to", "description")
collapsibleTreeNetwork(aft_tree_for_d3_wDes, attribute="description", zoomable = F, linkLength = 300)

Thanks! Violet

AdeelK93 commented 6 years ago

That's a strange one, would you happen to have an example of the aftv212_child_parent_class_tree_fixes.tsv file?

violetzh commented 6 years ago

The tsv file was sent via email. Thanks!

AdeelK93 commented 6 years ago

I don't think I got that email, could you send it to AdeelK@gwu.edu? Thanks

AdeelK93 commented 6 years ago

At first I thought this might have been some collision with a data.tree reserved word, but that doesn't appear to be the case. It looks like your use of the column name "description" is causing some issue with the json mappings in htmlwidgets, though I'm not totally sure why, though this error appears to afflict other htmlwidgets in some cases.

Fortunately, it should be an easy fix! Would you be alright with replacing "description" with "Description" in your last two lines of code?

violetzh commented 6 years ago

Yes. That does fix the error! Thanks!

From: Adeel Khan [mailto:notifications@github.com] Sent: Sunday, January 14, 2018 5:48 PM To: AdeelK93/collapsibleTree collapsibleTree@noreply.github.com Cc: Violet Zhang violet.v.zhang@gsk.com; State change state_change@noreply.github.com Subject: Re: [AdeelK93/collapsibleTree] Error in unclass(x) : cannot unclass an environment (#24)

EXTERNAL

At first I thought this might have been some collision with a data.tree reserved word, but that doesn't appear to be the case. It looks like your use of the column name "description" is causing some issue with the json mappings in htmlwidgets, though I'm not totally sure why, though this error appears to afflict other htmlwidgets in some cases.

Fortunately, it should be an easy fix! Would you be alright with replacing "description" with "Description" in your last two lines of code?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/AdeelK93/collapsibleTree/issues/24#issuecomment-357549380, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AevKbNLb_dqWS9keh3QCgqjOsUdUO2ZIks5tKoQ9gaJpZM4RaLd5.

GSK monitors email communications sent to and from GSK in order to protect GSK, our employees, customers, suppliers and business partners, from cyber threats and loss of GSK Information. GSK monitoring is conducted with appropriate confidentiality controls and in accordance with local laws and after appropriate consultation.