Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python R-如何将HTML代码嵌入Jupyter笔记本输出?_Python_Html_R_Styles_Jupyter Notebook - Fatal编程技术网

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

Python R-如何将HTML代码嵌入Jupyter笔记本输出?,python,html,r,styles,jupyter-notebook,Python,Html,R,Styles,Jupyter Notebook,我怎样才能使用R?实际上我想把Jupyter笔记本电脑的电池宽度设置为100%。在python中,此代码可以完美地工作: from IPython.core.display import HTML, display HTML("<style>.container { width: 100%; }</style>") 从IPython.core.display导入HTML,显示 HTML(“.container{width:100%;}”) R中是否有任何等价物 谢谢大

我怎样才能使用R?实际上我想把Jupyter笔记本电脑的电池宽度设置为100%。在python中,此代码可以完美地工作:

from IPython.core.display import HTML, display
HTML("<style>.container { width: 100%; }</style>")
从IPython.core.display导入HTML,显示
HTML(“.container{width:100%;}”)
R中是否有任何等价物


谢谢大家!

您可以使用
display\u html
功能在R中显示html代码,例如

//用于全宽
IRdisplay::display_html('.container{width:100%!important;}'))
//由于同源策略,这不适用于大多数站点,但本地文件没有问题
IRdisplay::显示html(“”)
请参阅:

将html代码和html表嵌入到IR内核jupyter R中的一些软件包提供html格式的表格,如“knitr”,因此,如果您想将这些表格放在笔记本中:

库(knitr)
图书馆(kableExtra)
dt%
可折叠(“条纹”)样式%>%
在上面加上标题(c(“=1,“第1组”=2,“第2组”=2,“第3组”=2))
显示html(toString(html表格))

最后,我编辑了
/anaconda/Lib/site packages/notebook/static/style/style.min.css
以始终“强制”100%宽度。我加了
宽度:100%
#笔记本电脑容器
。看起来您解决问题的方法比使用R要好。谢谢您的提示。除了默认值之外,您可能还可以创建一个自定义css文件,Jupyter将读取该文件。还有一些笔记本扩展可能会引起人们的兴趣。
// 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> ') 
  library(IRdisplay)

  display_html("your html code")
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))