Embed plotly html into reveal.js-presentation
Asked Answered
E

0

6

I am building a reveal.js-presentation. I have one graph, which I need to show upfront. However the graph is only generated later. Therefore I save it into as html. And load it using:

<style>
  .p_iframe iframe {
    width:90%;
    height:576px;
}
</style>

<div class="p_iframe">
<iframe frameborder="0" seamless='seamless' scrolling=no src="test.html"></iframe>
</div>

However this cuts off the legend if I open in Opera, Firefox or MS Edge. But if I use the iframe without div the graph doesn't come in the right size. How can I modify the css or the html such that the graph loads correctly? I need to open the presentation with a browser.

Update: The graph seems to work in Firefox and likely in Chrome too. Thanks to DJack for pointing it out. Is there any alternative code to make it work in other less used Browsers like MS Edge or Opera?

enter image description here

For the iframe-options I use this plotly help-page. There is an html version of how to embed plotly - but I do not understand how to modify it, such that I can load the plotly-html from local drive.

I generated the graph and the html using the following Rmd-Protocol:

---
title: "Untitled"
output: revealjs::revealjs_presentation
---

## Slide with R Code and Output
```{r}
library(plotly)

trace_0 <- rnorm(100, mean = 5)
trace_1 <- rnorm(100, mean = 0)
trace_2 <- rnorm(100, mean = -5)
x <- c(1:100)

data <- data.frame(x, trace_0, trace_1, trace_2)

p <- plot_ly(data, x = ~x, y = ~trace_0, name = 'trace 0', type = 'scatter', mode = 'lines') %>%
  add_trace(y = ~trace_1, name = 'trace 1', mode = 'lines+markers') %>%
  add_trace(y = ~trace_2, name = 'trace 2', mode = 'markers')

htmlwidgets::saveWidget(p,'test.html')
```

<style>
  .p_iframe iframe {
    width:90%;
    height:576px;
}
</style>

<div class="p_iframe">
<iframe frameborder="0" seamless='seamless' scrolling=no src="test.html"></iframe>
</div>
Evansville answered 13/4, 2018 at 11:44 Comment(4)
Using your code, the graph loads correctly.Headland
In which Browser? In Edge - it looks like the image above. In Opera it only works the first time I open it. The second time it looks like the image above. Only Firefox seems to work. Maybe I should ask whether there is any other way of loading the graph?Evansville
Chrome and firefox on Ubuntu.Headland
Thanks for pointing it out. I use Opera on Windows. I checked MS Edge before, but I must have forgotten to check Firefox.Evansville

© 2022 - 2024 — McMap. All rights reserved.