line / conflr

Post R Markdown documents to Confluence
https://line.github.io/conflr/
GNU General Public License v3.0
130 stars 28 forks source link

conflr with Plotly #15

Closed MadsTrolle closed 5 years ago

MadsTrolle commented 5 years ago

Plotly is a great and versatile plotting tool for R, especially in R markdown.

I think conflr does not currently support plotly graphs...

However, this would be a fantastic addition to an awesome and much needed tool!

yutannihilation commented 5 years ago

I think Confluence doesn't allow you to embed plot.ly. Can you?

MadsTrolle commented 5 years ago

I guess there is no easy way of embedding the plotly JavaScript object in confluence… Will look a bit more into if that's possible

A simple workaround would be turning the plotly item into a png, that's then included in the markdown like below.

`

p = plotly::plot_ly(pressure, x = ~temperature, y = ~pressure, mode = 'type', type = 'scatter')
plotly::orca(p, "tmp.png")
knitr::include_graphics("tmp.png")

`

The above deploys the image to our company confluence page using conflr. Not a pretty solution, though… And would require an installation of the orca command line program on the user side https://github.com/plotly/orca and version

yutannihilation commented 5 years ago

Thanks. FYI, if you are OK with the screenshots, using webshot is more handy.

https://bookdown.org/yihui/bookdown/html-widgets.html

For example, this should work (after you install PhantomJS by webshot::install_phantomjs()):

---
title: "plot.ly test"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  echo = TRUE,
  screenshot.force = TRUE
)

plot.ly test

library(plotly)

plot_ly(economics, x = ~pop)
MadsTrolle commented 5 years ago

Excellent advice - many thanks!

statquant commented 5 years ago

FYI some people in my company are using plotly in confluence and it is totally reactive. People put things in an iframe to make it work

statquant commented 5 years ago

image image

yutannihilation commented 5 years ago

Yeah, if HTML macro is available, it's possible. But, I don't think it's not always the case.

HTML macros are disabled by default https://confluence.atlassian.com/doc/html-macro-38273085.html

Unfortunately, I don't have access to a Confluence with HTML macro enabled... Do you want to try a PR for this feature?

arisehkawamura commented 5 years ago

@statquant Can you share us the full HTML code?

statquant commented 5 years ago

Hello @yutannihilation if you can drive me a bit I'd like to try to PR this, I think that would really make a huge difference to this package and our work flow in general. I have access to confluence with html macro

yutannihilation commented 5 years ago

A PR for this will be really appreciated!

statquant commented 5 years ago

Would you have some tips and pointers to get me started ?

yutannihilation commented 5 years ago

Sorry, I don't have much time to write some developer guide... I guess you can add something like replace_htmlwidgets() in this function:

https://github.com/line/conflr/blob/38143bb8920cebcf7e20e61186c070a5b2bc14fa/R/translate.R#L12