Kitware / candela

Visualization components for the web
https://candela.readthedocs.io
Apache License 2.0
116 stars 29 forks source link

Include candela widget in an R Markdown document? #524

Closed smach closed 6 years ago

smach commented 6 years ago

Is it possible to include a candela htmlwidget in an R Markdown document? Is so, how?

When I run candela('LineUp', data=mtcars, fields=c('_row', 'mpg', 'wt', 'disp')) in RStudio and then click the "publish to Rpubs" button in the RStudio viewer, that works to show the LineUp graphic on Rpubs.. But if I try to include the same code within an HTML R Markdown document, the LineUp graphic doesn't display in the document. Is this possible to include a candela graphic in an R Markdown graphic (without using Shiny) and I'm just doing it incorrectly? I tried with option results = asis but that didn't help. Thanks.

jeffbaumes commented 6 years ago

Thanks for reporting this. Yes, there was a general issue with exporting markdown HTML, which is being addressed in #525. To test it out, run the following to install the branch with the fix:

devtools::install_github('Kitware/candela', subdir='R/candela', ref='r-full-url')

With this fix, most plots will render fine, but LineUp still has an issue where it renders to the upper left corner of the page. See this example markdown:

---
title: "LineUp"
author: "Jeffrey Baumes"
date: "1/22/2018"
output: html_document
---

## Using Candela - Scatterplot

Creating a scatterplot seems to render fine.

```{r}
library(candela)
candela('ScatterPlot', data=mtcars, x='mpg', y='wt', color='disp')

Using Candela - LineUp bug

Creating a LineUp plot will render, but will show up in the upper left corner of the page, overlaying other text.

candela('LineUp', data=mtcars, fields=c('_row', 'mpg', 'wt', 'disp'))


Rendered it looks like this:

![image](https://user-images.githubusercontent.com/81305/35223353-0edfac82-ff4f-11e7-8db4-e2b3d3a9b70c.png)
jeffbaumes commented 6 years ago

For LineUp, you may also be interested in the alternate LineUp R widget by @sgratzl which was released recently:

https://github.com/sgratzl/lineup_htmlwidget

smach commented 6 years ago

Thanks very much. I did notice that when trying with Shiny, LineUp rendered at top left (and covered my text). I'll try that R Markdown code at home tonight. That looks like it renders in its own column so I can still have other things on the page, which would be good. I tried the @sgratzl lineup widget, but it didn't seem to change rankings when columns resized (or show distribution in column headers). So that one appears great for visualizing rankings as-is but not, as far as I could see, for additional exploration. [Unless the interactivity needs Shiny] Thanks again.

jeffbaumes commented 6 years ago

Great, let me know how it goes.

Note that LineUp only appears to render in its own column because my browser window was very wide. If I had a narrower window it would overlap the main text.

Also, #525 was merged so you now only need to reinstall Candela normally to get the fix.

devtools::install_github('Kitware/candela', subdir='R/candela')
sgratzl commented 6 years ago

@smach can you elaborate the error on my lineup widget or file an issue, please? Cause when I'm using https://sgratzl.github.io/lineupjs_docs/R/ I do see summary headers + when I drag one column onto the other column width changes have an effect on the ranking.

smach commented 6 years ago

@sgratzl Thank you for the response. Whoops very sorry, I had installed the Caleydo/lineup_htmlwidget version, which is what I thought Jeff was referring to . The one in your repo is working properly. (And sorry for the tangent discussion on your project, @jeffbaumes )

smach commented 6 years ago

@jeffbaumes I reinstalled and the LineUp graph is indeed displaying in my R Markdown document now (but still, as you said, in the upper left corner of the document).

sgratzl commented 6 years ago

@smach thx for checking. I'm happy to hear that it works

jeffbaumes commented 6 years ago

@smach Glad you have something working. I'll close for now but feel free to open another if you have more issues.