keeganhines / vivagRaph

12 stars 1 forks source link

data formatting from R #1

Closed keeganhines closed 9 years ago

keeganhines commented 9 years ago

Currently broken because the dataframes from R are creating js objects that are malformed. The js code in vivagRaph.js expects the edge and node objects to be of the form

var networkData={
nodes:[
{nodeName:'Bill', group:1},
{nodeName:'Ted', group:1}
        ],
links:[
{source:0,target:1,value:1}
        ]
}

But the object that is created by htmlwidgets is

{
nodes:{
nodeName:['Bill', 'Ted'],
group: [1 , 1]
}, 
edges:{
source: [0],
target: [1],
value: [1]
}
}

Need to reformat things from the R side, or alter vivagRaph.js

timelyportfolio commented 9 years ago

Sorry on my phone so cannot link to line numbers but there are helpers in htmlwidgets starting line 509 https://github.com/ramnathv/htmlwidgets/blob/master/inst/www/htmlwidgets.js. See line 31 https://github.com/christophergandrud/networkD3/blob/master/inst/htmlwidgets/forceNetwork.js for an example.

The choice was made to use the sparsest JSON representation and then transform in JavaScript.

keeganhines commented 9 years ago

was able to use jsonlite to fix this; now takes inputs as described in the README and produces a network. this is commit a88829...