Display python plotly graph in RMarkdown html document

徘徊边缘 提交于 2019-12-05 14:52:24

Here is what I did:

  1. used plotly offline:
    • replace import plotly.plotly as py by import plotly.offline as py
    • no need to set username and api key in offline mode.
  2. used py.plot(fig, filename = "styled-scatter.html", auto_open=False):
    • py.iplot() is for Jupyter notebooks (it embeds the plot directly into the Notebook)
    • auto_open = False argument is to avoid that the plot pops up.
  3. embedded the html plot into the Rmarkdown by using the following:

    ```{r, echo=FALSE}
    htmltools::includeHTML("styled-scatter.html")
    ```
    

    and here is the result:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!