Closed Jinchao-Yu closed 4 years ago
@Jinchao-Yu Thanks for the bug report.
Can you provide - it would be a good help - a reproducible, minimal example of this problem?
Hi @paul-shannon . First of all, it is rather an improvement than a bug. Because with json input we can use preset coordinates but we cannot with dataframe. In fact, it is better if a small doc can be provided to explain which column names are used by cyjshiny, for example for nodes, "id". And as I tested, "parent" is also one, useful for composite nodes. Now in this issue, I suggest adding "x", "y", which can be loaded into json as position: {x: 100, y: 100}
(ref: https://js.cytoscape.org/#notation/position)
A minimal example, based on your inst/examples/dataFrameGraphWithAnimation/app.R is (1) add x and y for tbl.nodes
tbl.nodes <- data.frame(id=c("A", "B", "C"),
type=c("kinase", "TF", "glycoprotein"),
x=c(0, 100, 200), # modified
y=c(200, 100, 0), # modified
lfc=c(1, 1, 1),
count=c(0, 0, 0),
stringsAsFactors=FALSE)
and (2) use "preset" as default layout for output$cyjShiny:
output$cyjShiny <- renderCyjShiny({
cyjShiny(graph=graph.json, layoutName="preset") # modifed
})
Excellent - thank you. I will work on this before the end of the week.
On Nov 20, 2019, at 1:39 AM, Jinchao Yu notifications@github.com wrote:
Hi @paul-shannon . First of all, it is rather an improvement than a bug. Because with json input we can use preset coordinates but we cannot with dataframe. In fact, it is better if a small doc can be provided to explain which column names are used by cyjshiny, for example for nodes, "id". And as I tested, "parent" is also one, useful for composite nodes. Now in this issue, I suggest adding "x", "y", which can be loaded into json as position: {x: 100, y: 100} (ref: https://js.cytoscape.org/#notation/position)
A minimal example, based on your inst/examples/dataFrameGraphWithAnimation/app.R is (1) add x and y for tbl.nodes
tbl.nodes <- data.frame(id=c("A", "B", "C" ),
type=c("kinase", "TF", "glycoprotein" ),
x=c(0, 1, 2), # modified
y=c(2, 1, 0), # modified
lfc=c(1, 1, 1 ),
count=c(0, 0, 0 ),
stringsAsFactors=FALSE) and (2) use "preset" as default layout for output$cyjShiny:
output$cyjShiny <- renderCyjShiny({ cyjShiny( graph=graph.json, layoutName="preset") # modifed
})
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
@Jinchao-Yu Despite appearances, I am working on this - in the midst of some other tasks. I have just standardized and unified json graph and json style input. I had used a few different versions of these file formats before; they now all get transformed to a standard data structure when read in.
This sets the stage for implementing your suggestion - to heed x and y positions if supplied in a data.frame. Coming soon...
@Jinchao-Yu
Here's the convention I settled on, using xPos
and yPos
data.frame column names:
tbl.nodes <- data.frame(id=c("A", "B", "C"),
type=c("kinase", "TF", "glycoprotein"),
xPos=c(0, 100, 800),
yPos=c(200, 100, 150),
lfc=c(1, 1, 1),
count=c(0, 0, 0),
stringsAsFactors=FALSE)
Resulting in this layout:
If you are feeling bold, these changes are in the refactor-graph-dataFrame-toJSON
branch, package version 1.0.6, tested via "make && make test" and with a simple demo in
inst/examples/dataFrameGraphWithAnimation/app.R
Your feedback is welcome.
Thank you. I'll try in a week.
On Fri, Dec 6, 2019 at 2:48 AM Paul Shannon notifications@github.com wrote:
@Jinchao-Yu https://github.com/Jinchao-Yu Here's the convention I settled on, using xPos and yPos data.frame column names:
tbl.nodes <- data.frame(id=c("A", "B", "C"), type=c("kinase", "TF", "glycoprotein"), xPos=c(0, 100, 800), yPos=c(200, 100, 150), lfc=c(1, 1, 1), count=c(0, 0, 0), stringsAsFactors=FALSE)
Resulting in this layout: [image: image] https://user-images.githubusercontent.com/2480712/70287852-4097c980-1785-11ea-9f38-936a3ab14a1d.png
If you are feeling bold, these changes are in the refactor-graph-dataFrame-toJSON branch, package version 1.0.6, tested via "make && make test" and with a simple demo in inst/examples/dataFrameGraphWithAnimation/app.R Your feedback is welcome.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cytoscape/cyjShiny/issues/23?email_source=notifications&email_token=AHGUWTPCJRZ3RLOR56ZWSWLQXGVQVA5CNFSM4JPBBAVKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGCX3VQ#issuecomment-562396630, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHGUWTIFH5OEDDYK42P6VU3QXGVQVANCNFSM4JPBBAVA .
@paul-shannon Thanks. It works in my case using this new branch. I need to remind you that you use "xPos" and "yPos" instead of my suggested "x" and "y". But in this case, you may need to modify cyjShiny::setNodePositions for consistency as it takes a tibble of 3 columns: "id", "x", and "y".
@Jinchao-Yu Following your suggestion, "xPos" and "yPos" are replaced by simple "x" and "y" columns in the nodes data.frame. inst/unitTests/testGraphsToJSON.R
tests all pass, as does inst/examples/dataFrameGraphWithAnimation/app.R
. I'll be grateful if you could run your tests as well, as an extra precaution, before I merge this branch back into master.
merged branch with master.
note that ```style_fileparameter to cyjShiny constructor now follows our camelCase standard:
styleFile````
@paul-shannon Thanks. I replaced xPos and yPos and it worked well (I had noticed styleFile change last time and modified accordingly). Bravo.
In "preset" layout, normally, data "position": {"x"=nn, "y"=mm} can be loaded and used as coordinates. However, dataFramesToJSON cannot load "x" and "y" (or anything like position.x) from dataframe. Therefore, if one uses dataframe as graph source, "preset" layout in fact doesn't work.
This can be very problematic if one wants to load predefined network layout, or wants to show a big network (ex: 1000+ nodes) using a rapid layout algorithm from a 3rd party tool like igraph.
There is a work-around way by using setNodePositions(session, tbl_pos) where tbl_pos has columns of "id", "x", "y", although this method is not optimal. The best solution is to make dataFramesToJSON reads "x" and "y" from tbl.nodes correctly so that "preset" can work.