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

Sankey Diagram does not show up in the Rmarkdown but in the local Rstudio #726

Open
MengyingLi opened this issue Jun 11, 2017 · 1 comment

Comments

@MengyingLi
Copy link

MengyingLi commented Jun 11, 2017

Hi I am using Sankey Diagram and it works perfectly in my local. However, when I tried to print it to Rmarkdown, it did not work at all. I have followed @ramnathv 's other post in including the options in the chunk and print in the end. This trick works well for all other RCharts but not for Sankey Diagram. The related piece of code is showing as below and in this example, only p2 showed up not p1

````{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = FALSE)
    library(rCharts)
    library(knitr)
    ```

    ```{r set-options, echo=FALSE, cache=FALSE}
    options(RCHART_WIDTH = 1000, RCHART_HEIGHT = 400)
    ```


    ```{r, echo = FALSE, results = 'asis'}
    load("/home/user/R/df_sankey_example.rda")
    sankeyPlot_fct=function(df){
      sankeyPlot <- rCharts$new()


      sankeyPlot$setLib('/home/user/rcharts_d3_sankey/')

      sankeyPlot$setTemplate(
        afterScript = "
    <script>
    // to be specific in case you have more than one chart
    d3.selectAll('#{{ chartId }} svg path.link')
      .style('stroke', function(d){
        //here we will use the source color
        //if you want target then sub target for source
        //or if you want something other than gray
        //supply a constant
        //or use a categorical scale or gradient
        return d.source.color;
      })
     //note no changes were made to opacity
     //to do uncomment below but will affect mouseover
     //so will need to define mouseover and mouseout
     //happy to show how to do this also
     .style('stroke-opacity', .7) 
    </script>
    ")
    sankeyPlot$set(
        data = df,
        nodeWidth = 25,
        nodePadding = 10,
        layout = 32,
        width = 1800,
        height = 900
      )

      sankeyPlot
    }

    ```{r, echo=FALSE, cache=T, results='asis', comment=NA}
    p1= sankeyPlot_fct(df.sankey.plot)
    p1$print('chart1', include_assets=T)
    ````
    ```{r, echo=FALSE, cache=T, results='asis', comment=NA}
p2 <- nPlot(mpg ~ wt, group = 'cyl', data = mtcars, type = 'scatterChart')
p2$print('chart2', include_assets=T)
@henclewood
Copy link

@MengyingLi, did you manage to generate an rCharts Sankey Diagram ("p1") in RMarkdown, html, file?

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

2 participants