首页 > 解决方案 > 如何在 R 中打印 HTML

问题描述

我有这个

<div style="margin:auto;text-align:center">
  <strong>Types per year</strong>
  <br/>
  <div id="htmlwidget-342a290aea162ba34746" class="streamgraph html-widget" style="width:960px;height:500px;"></div>
  <div id="htmlwidget-342a290aea162ba34746-legend" style="width:960" class="streamgraph html-widget-legend"><center><label style='padding-right:5px' for='htmlwidget-342a290aea162ba34746-select'></label><select id='htmlwidget-342a290aea162ba34746-select' style='visibility:hidden;'></select></center></div>
  <script type="application/json" data-for="htmlwidget-342a290aea162ba34746">{"x":{"data":{"key":["Industrial.compound","Pesticide","Pharmaceutical","Industrial.compound","Pesticide","Pharmaceutical","Industrial.compound","Pesticide","Pharmaceutical","Industrial.compound","Pesticide","Pharmaceutical"],"value":[3.21469787709497,0.312979157894737,0.124318181818182,2.60063721925134,0.268401470588235,0.145491329479769,3.80744464705882,0.51568,0.2358755,0.51034125,0.297461538461538,0],"date":["2015-04-24","2015-04-24","2015-04-24","2016-04-24","2016-04-24","2016-04-24","2017-04-24","2017-04-24","2017-04-24","2018-04-24","2018-04-24","2018-04-24"]},"markers":null,"annotations":null,"offset":"silhouette","interactive":true,"interpolate":"cardinal","palette":"Spectral","text":"black","tooltip":"black","x_tick_interval":1,"x_tick_units":"yr","x_tick_format":"%Y","y_tick_count":0,"y_tick_format":",g","top":20,"right":40,"bottom":30,"left":50,"legend":true,"legend_label":"Type: ","fill":"brewer","label_col":"black","x_scale":"date"},"evals":[],"jsHooks":[]}</script>
</div>

我想在 R 中打印绘图,但我不知道如何使用 html 来打印。

你能帮助我吗?

标签: htmlrshiny

解决方案


由于您将其标记为 Shiny,我将假设您希望在闪亮的应用程序中包含原始 HTML。在这种情况下,您可以使用 HTML 标签

library(shiny)
# add the below in your ui.R script

tags$div(

HTML( <your raw HTML goes here> )

)

有关更多详细信息,请参阅https://shiny.rstudio.com/articles/html-tags.html,向下滚动到“原始 HTML”部分。


推荐阅读