将plotly html嵌入reveal.js-presentation中

时间:2018-04-13 11:44:18

标签: html css r plotly reveal.js

我正在构建reveal.js演示文稿。我有一张图,我需要提前显示。但是,图表仅在稍后生成。因此我将其保存为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>

然而,如果我在Opera,Firefox或MS Edge中打开,这会切断传奇。但是,如果我使用iframe而没有div,则图表的大小不合适。 如何修改csshtml以便图表正确加载?我需要使用浏览器打开演示文稿。

更新:图表似乎在Firefox中运行,也可能在Chrome中运行。感谢DJack指出它。是否有任何替代代码可以使其在其他较少使用的浏览器中工作,如MS Edge或Opera?

enter image description here

对于iframe - 选项,我使用this plotly help-page。有一个如何嵌入的html版本 - 但我不明白如何修改它,这样我可以从本地驱动器加载plotly-html。

我使用以下Rmd-Protocol生成图表和html:

---
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>

0 个答案:

没有答案
相关问题