christophergandrud / d3Network

Tools for creating D3 JavaScript network graphs from R.
http://christophergandrud.github.io/d3Network/
171 stars 56 forks source link

Shiny support #11

Closed christophergandrud closed 10 years ago

christophergandrud commented 10 years ago
christophergandrud commented 10 years ago

Current idea:

In server.R wrap the d3Network function call in capture.output. Then use renderUI and htmlOutput in ui.R.

The problem: this returns the script for the plot in a block div, so it is just text.

Probably need a new Output function to return only the raw script into the webpage.

christophergandrud commented 10 years ago

Current working example being developed at: https://github.com/christophergandrud/d3ShinyExample

christophergandrud commented 10 years ago

Currently the d3Network function call does not go through capture.output. Instead I used renderPrint and htmlOutput.

In addition:

    tags$head(
        tags$script(src = 'http://d3js.org/d3.v3.min.js')
    ),

Is entered in the shinyUI. For some reason the script was not read when it is outputted later on.

This all consistently builds the plots. The remaining issues are:

  1. The plots are not returned in the fluid layout container.
  2. Each time a new input is given a new plot is outputted in addition to the previous plots.
christophergandrud commented 10 years ago

Issue solved in c6b44a392f5cccd6d23afa9338bca12126036f7e

Building on @johndharrison pull request, all d3Network functions have a new argument called parentElement this allows the user to specify the resulting svg graph's parent element.

See https://github.com/christophergandrud/d3ShinyExample for an example.

amberalpha commented 10 years ago

Hi Chris - hope I am now posting in the right place and that I am not too off-topic.

parentElement worked straight out of the box for me, so I have the network inside a tabPage. Really nice. That's a magnitude 0 understatement.

I now just want to get it up on spark, but it is on V2.15 with no plans to upgrade to V3 AFAIK, it will be deprecated and not upgraded. d3Networks of course requires V3 - could I just downgrade it's 'required' field, or is this not a good idea?

christophergandrud commented 10 years ago

Great to hear that it's working for you/

You could try downgrading the required field to 2.15. I'm not sure that it would work differently, I just haven't tested it.

Let me know if anything funny happens.

amberalpha commented 10 years ago

I'm waiting for a new (shiny) account - that's clearly the right direction to go, i.e. forwards to version 3.x

Related question: I have an application with large heirarchical tree, and can show it fine with d3SimpleNetwork(), the data is already naturally organised this way, this being a standard table representation of this kind of many-one relationship.

However it would be perhaps more appropriate to use d3Tree, and here it gets more tricky. As you say in your notes, 'R doesn't make it super easy to create these types of lists'. Rather than re-inventing the wheel, I wonder if someone out there does not have an existing solution to this transformation... I wonder if it could be put up on a list or stackoverflow or somesuch? I'm not sure where is best, these days.

On 26 May 2014 12:39, Christopher Gandrud notifications@github.com wrote:

Great to hear that it's working for you/

You could try downgrading the required field to 2.15. I'm not sure that it would work differently, I just haven't tested it.

Let me know if anything funny happens.

— Reply to this email directly or view it on GitHubhttps://github.com/christophergandrud/d3Network/issues/11#issuecomment-44181423 .

christophergandrud commented 10 years ago

The R Stack Overflow would probably be a good place to post that question.

(you could file a feature request here, but I think it will get more attention if you ask the question generally on Stack Overflow)