rstudio / revealjs

R Markdown Format for reveal.js Presentations
Other
325 stars 86 forks source link

Add html plot to slide in `rmarkdown` #153

Closed rleyvasal closed 2 years ago

rleyvasal commented 2 years ago

I want to insert plot.html (created in python Plotly) into my slides, but there is no option to do it in rmarkdown

Inserting the plot works into slides with the following code:

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

</style>

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

Is there an easier way to do the above in rmarkdown ?

the following does not work well(plot squeezed):


# iframe not working to insert html

<iframe src=""plot.html"> </iframe>
cderv commented 2 years ago

You should be able to use HTML code inside your Markdown document. Can you share plot.html so that I can try ? What is not working exactly ? Can you share a screenshot of the slide ?

rleyvasal commented 2 years ago

using iframe plot does not show

iframe

using HTML the plot shows

html_slide

Code to replicate

# HTML plot iframe not working to insert html

<iframe src="plot.html"> </iframe>

# HTML Plot {data-transition="zoom"}

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

</style>

<div class="p_iframe">
<iframe frameborder="0" seamless='seamless' scrolling=no src="plot.html"></iframe>
</div>
cderv commented 2 years ago

I don't have plot.html to replicate.

rleyvasal commented 2 years ago

plot.zip

rleyvasal commented 2 years ago

Problem solved: just had to add class="stretch" as shown in code below. Feel free to close this issue

<iframe class="stretch" src="plot.html"> </iframe>
cderv commented 2 years ago

Oh ok. so that is a matter of CSS for your inserted iframe. stretch class will trigger a feature in reveal to compute width to fit the available space.

Glad it works for this !

rleyvasal commented 2 years ago

Adding a pause . . . before iframe plot causes the same issue - html image squeezed and cannot be seen.


. . .

<iframe class="stretch" src="plot.html"> </iframe>