Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
693 views
Welcome To Ask or Share your Answers For Others

1 Answer

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>")

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...