How to store r ggplot graph as html code snippet

前端 未结 3 1447
你的背包
你的背包 2021-02-10 01:52

I am creating an html document by creating various objects with ggplotly() and htmltools functions like h3() and html(). Then I submit th

3条回答
  •  余生分开走
    2021-02-10 02:49

    If you want to save the plot as a dynamic plotly graph, you could use htmlwidgets::saveWidget. This will produce a stand-alone html file.

    Here is a minimal example:

    library(tidyverse);
    library(plotly);
    library(htmlwidgets);
    
    df <- data.frame(x = 1:25, y = c(1:25 * 1:25))
    gg <- ggplot(df,aes(x = x, y = y)) + geom_point()
    
    # Save ggplotly as widget in file test.html
    saveWidget(ggplotly(gg), file = "test.html");
    

提交回复
热议问题