R - 如何将HTML代码嵌入到Jupyter笔记本输出中?

时间:2016-06-13 15:38:48

标签: python html r styles jupyter-notebook

如何使用R执行this之类的操作?其实我想将Jupyter笔记本电脑的宽度设置为100%。在python中,这段代码完美无缺:

from IPython.core.display import HTML, display
HTML("<style>.container { width: 100%; }</style>")

R中是否有任何等效物?

谢谢!

2 个答案:

答案 0 :(得分:1)

您可以使用display_html函数显示R中的html代码,例如

// for full width
IRdisplay::display_html('<style>.container { width:100% !important; }</style>')

// this does not work with most sites due to same-origin policy, but no problem with local files   
IRdisplay::display_html('<iframe src="http://www.w3schools.com" width=1000, height=1000></iframe> ') 

请参阅:SecurityError: Blocked a frame with origin from accessing a cross-origin frame

答案 1 :(得分:0)

将html代码和html表嵌入到IR内核jupyter中

  library(IRdisplay)

  display_html("your html code")

R中的某些程序包会以html格式(例如“ knitr”)提供表格,因此,如果要将这些表格放在笔记本中:

library(knitr)
library(kableExtra)

dt <- mtcars[1:5, 1:6]
options(knitr.table.format = "html") 
html_table= kable(dt) %>%
   kable_styling("striped") %>%
   add_header_above(c(" " = 1, "Group 1" = 2, "Group 2" = 2, "Group 3" = 2))

display_html(toString(html_table))