可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
Instead of rendering the HTML, it just displays it as plaintext. Is there any way to change that behavior?
回答1:
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 hello") # Cell 3 ------------------------------------------------------------------ display_markdown("[this](http://google.com)") # Cell 4 ------------------------------------------------------------------ display_png(file="shovel-512.png") # Cell 5 ------------------------------------------------------------------ display_html("")

回答2:
I found a simpler answer, for the initial, simple use case.
If you call xtable without wrapping it in a call to print, then it totally works. E.g.,
library(xtable) data(cars) model
回答3:
In Jupyter, you can use Markdown. Just be sure to change the Jupyter cell from a code cell to a Markdown cell. Once you have done this you can simply place a double dollar sign ("$$") before and after the LaTex you have. Then run the cell.
The steps are as follows: 1. Create a Markdown cell. 2. $$ some LaTex $$ 3. Press play button within Jupyter.
回答4:
Defining the following function in the session will display objects returned by xtable as html generated by xtable:
repr_html.xtable
Without the repr_html.xtable
function, because the returned object is also of class data.frame
, the display system in the kernel will rich display that object (=html table) via repr::repr_html.data.frame
.
Just don't print(...)
the object :-)