如何在Jupyter(R)中渲染LaTeX / HTML? [英] How to render LaTeX / HTML in Jupyter (R)?

查看:1146
本文介绍了如何在Jupyter(R)中渲染LaTeX / HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用Jupyter和R,我想知道是否有一种很好的方式来显示HTML或LaTeX输出。



下面是一些我希望的代码示例:

  library(xtable)
x< - runif(500,1,50)
y< ; - x + runif(500,-5,5)
model <-lm(y〜x)
print(xtable(model),type ='html')

不是呈现HTML,而是将其显示为纯文本。有什么方法可以改变这种行为吗?

repr (用于设置选项)和 IRdisplay 将适用于HTML。其他人可能知道乳胶。

 #Cell 1 ----------------- ------------------------------------------------- 
$ b $ library(xtable)
library(IRdisplay)
library(repr)

data(tli)
tli.table< - xtable (tli [1:20,])
digits(tli.table)< - 矩阵(0:4,nrow = 20,ncol = ncol(tli)+1)

选项(repr.vector.quote = FALSE)
$ b display_html(paste(capture.output(print(head(tli.table),type ='html')),collapse =,sep = ))


#单元格2 -------------------------------- ----------------------------------

display_html(< span style = 'color:red; float:right'> hello< / span>)

#Cell 3 --------------------- ---------------------------------------------

display_markdown([this](http://google.com))

#单元格4 ------------------- -----------------------------------------------

display_png(file =shovel-512.png)

#单元格5 ---------------------- - ------------------------------------------

display_html(< table style ='width:20%; border:1px solid blue'>< tr>< td style ='text-align:right'> cell 1< / td>< / tr> ;< / table>)

p>

I just started using Jupyter with R, and I'm wondering if there's a good way to display HTML or LaTeX output.

Here's some example code that I wish worked:

library(xtable)
x <- runif(500, 1, 50)
y <- x + runif(500, -5, 5)
model <- lm(y~x)
print(xtable(model), type = 'html')

Instead of rendering the HTML, it just displays it as plaintext. Is there any way to change that behavior?

解决方案

A combination of repr (for setting options) and IRdisplay will work for HTML. Others may know about latex.

# Cell 1 ------------------------------------------------------------------

library(xtable)
library(IRdisplay)
library(repr)

data(tli)
tli.table <- xtable(tli[1:20, ])
digits(tli.table) <- matrix( 0:4, nrow = 20, ncol = ncol(tli)+1 )

options(repr.vector.quote=FALSE)

display_html(paste(capture.output(print(head(tli.table), type = 'html')), collapse="", sep=""))


# Cell 2 ------------------------------------------------------------------

display_html("<span style='color:red; float:right'>hello</span>")

# Cell 3 ------------------------------------------------------------------

display_markdown("[this](http://google.com)")

# Cell 4 ------------------------------------------------------------------

display_png(file="shovel-512.png")

# Cell 5 ------------------------------------------------------------------

display_html("<table style='width:20%;border:1px solid blue'><tr><td style='text-align:right'>cell 1</td></tr></table>")

这篇关于如何在Jupyter(R)中渲染LaTeX / HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆