.Rmd中使用的R - kable()不会在笔记本中显示输出(R - kable() used in .Rmd does not show output in notebook)

我刚开始使用kableExtra库来使我的表格在PDF输出中看起来更好。
但是当我在R Notebook文件中使用kable()函数时,它不显示输出。 相反,我看到输出应该是一个很大的空白区域。
这是一个截图:

在这里输入图像描述 当我把文件Knit成PDF时,我可以看到输出。
这是一个截图:
在这里输入图像描述
有什么办法可以使输出出现在Notebook和PDF中? 这是我的代码:

---
title: "R Notebook"
output:
  pdf_document: default
  html_notebook: default
---

```{r  message=FALSE, warning=FALSE}
library(knitr)
library(kableExtra)
library(dplyr)
#plot(cars)
```

```{r}
 cars %>% 
  slice(1:10) %>% 
  select(speed, dist) %>% 
  kable(format = "latex", booktabs = T) %>% 
  column_spec(column = 1:2, width = "0.5in")

```

I just started using kableExtra library to make my tables look better in the PDF output.
But when I use kable() function in R Notebook file, it does not show the output. Instead I see a large white space where the output should be.
Here is a screenshot:

enter image description here When I Knit the file to PDF I can see the output.
Here is a screenshot:
enter image description here
Is there a way I can make the output appear both in the Notebook and PDF? Here is my code:

---
title: "R Notebook"
output:
  pdf_document: default
  html_notebook: default
---

```{r  message=FALSE, warning=FALSE}
library(knitr)
library(kableExtra)
library(dplyr)
#plot(cars)
```

```{r}
 cars %>% 
  slice(1:10) %>% 
  select(speed, dist) %>% 
  kable(format = "latex", booktabs = T) %>% 
  column_spec(column = 1:2, width = "0.5in")

```
2022-09-01 19:09

满意答案

您必须为每个输出设置不同的kable format参数,并在块选项中指定results = 'asis'

对于HTML /笔记本

```{r, results='asis'}
cars %>% 
  slice(1:10) %>% 
  select(speed, dist) %>% 
  kable(format = "html", booktabs = T) %>% 
  column_spec(column = 1:2, width = "0.5in")
```

对于PDF

```{r, results='asis'}
cars %>% 
  slice(1:10) %>% 
  select(speed, dist) %>% 
  kable(format = "latex", booktabs = T) %>% 
  column_spec(column = 1:2, width = "0.5in")
```

You have to set a different kable format parameter for each output and specify results = 'asis' in chunk options.

For HTML / Notebook:

```{r, results='asis'}
cars %>% 
  slice(1:10) %>% 
  select(speed, dist) %>% 
  kable(format = "html", booktabs = T) %>% 
  column_spec(column = 1:2, width = "0.5in")
```

For PDF:

```{r, results='asis'}
cars %>% 
  slice(1:10) %>% 
  select(speed, dist) %>% 
  kable(format = "latex", booktabs = T) %>% 
  column_spec(column = 1:2, width = "0.5in")
```

相关问答

更多

.yml中的设置不会在呈现的.Rmd中显示(Settings in .yml do not show up in rendered .Rmd)

该问题似乎来自使用bookdown::html_document2而不是使用rmarkdown函数html_document 。 在这里使用RStudio提供的模板,我对这些设置进行了一些编辑,添加了theme: flatly : name: "my-website" navbar: title: "My Website" left: - text: "Home" href: index.html - text: "About" href: abou...

.Rmd中使用的R - kable()不会在笔记本中显示输出(R - kable() used in .Rmd does not show output in notebook)

您必须为每个输出设置不同的kable format参数,并在块选项中指定results = 'asis' 。 对于HTML /笔记本 : ```{r, results='asis'} cars %>% slice(1:10) %>% select(speed, dist) %>% kable(format = "html", booktabs = T) %>% column_spec(column = 1:2, width = "0.5in") ``` 对于PDF : `...

使用xtable或knitr :: kable抑制.Rmd文件中的自动表名和编号(Suppress automatic table name and number in an .Rmd file using xtable or knitr::kable)

事实证明,我需要在YAML部分添加以下内容: header-includes: - \usepackage{caption} 以及代码块之前的某个地方: \captionsetup[table]{labelformat=empty} 现在它有效: --- title: "Suppress automatic table name and number" output: pdf_document header-includes: - \usepackage{caption} --...

为什么R引用旧的.Rmd文件(why is R referring to old .Rmd file)

我相信错误是我没有告诉它覆盖那里的旧文件。 output$downloadReport <- downloadHandler( filename = function() { paste('report', sep = '.', switch( input$format, PDF = 'pdf', HTML = 'html', Word = 'docx' )) }, content = function(file) { src <- normalizePath('shinyAppTest1...

访问.rmd文件的名称并在R中使用(Access name of .rmd file and use in R)

rmarkdown::metadata为您提供R Markdown的元数据列表,例如rmarkdown::metadata$title将是您文档的标题。 一个例子: --- title: "Beamer Presentation Title" author: "My Name" date: "10\. Mai 2015" output: beamer_presentation --- ## Slide 1 Print the title in a code chunk. ```{r} rma...

结合Shiny app和Rmd文件(Combining Shiny app and Rmd file)

我使用这个问题中解释的方法解决了这个问题 。 我希望它可以帮助那些有同样问题的人。 I solved the problem using a method which is explained in this question. I hope that it helps people who have the same problem.

来自另一个Rmd中的Rmd文件的源代码(Source code from Rmd file within another Rmd)

进一步搜索后,我找到了解决方案。 knitr中有一个包选项,可以设置为更改处理重复块的行为,在标签后附加一个数字而不是出错。 请参阅https://github.com/yihui/knitr/issues/957 。 要设置此选项,请使用options(knitr.duplicate.label = 'allow') 。 为了完整起见,我编写的函数的完整代码是 source_rmd <- function(file, local = FALSE, ...){ options(knitr.du...

Knitr和kable没有找到数据框(Knitr and kable not finding data frame)

感谢@Molx的回答,感谢@ D.Mercer的评论。 降价代码中的所有内容。 ```{r echo=FALSE,results='asis'} library(knitr) a<-c(1,2,3,4,5,6) b<-c(1,2,3,4,5,6) tab<-data.frame(a,b) knitr::kable(tab) ``` Thanks to @Molx for the answer, and @D.Mercer for the comments. Everything in the m...

如何在从.rmd编织到Word时使用格式化Kable表(带书)(How to format kable table when knit from .rmd to Word (with bookdown))

Pandoc 转换为单词是通过pandoc 。 目前pandoc只创建四种类型的表, 简单的桌子 multiline_tables grid_tables pipe_tables 其中一些支持的格式在pander和pandoc手册 p 35-39中进行了批判 。 因此,您无法使用pandoc创建当前剥离的表 。 您还可以很好地总结如何在rmarkdown.rstudio中使用表格。 潘多克v2 看下面大卫的好消息 Pandoc The conversion to word is made via ...

knit pdf中的kable()看起来过大了(kable() in knit pdf appears oversized)

有很多选项可以在单元格中拆分文本,或者如果使用pander太宽则拆分表格,例如: > pander(tble, split.cells = 20, split.table = Inf) -------------------------------------------------------------------------------------------------------------------------------------------------------------...

相关文章

更多

nutch与起点R3集成之笔记(四)

通过“nutch与起点R3集成之笔记(一、二、三)”中的步骤,我们可以建立起一个行业内部网的搜索引擎, ...

nutch与起点R3集成之笔记(一)

百度、google帮我们找Internet的信息,但对于一个行业内部网(intranet)来说,百度、 ...

javax.imageio.IIOException: Can't create output stream!的解决方案

ImageIO.write(image, "jpeg", response.getOutputStre ...

nutch与起点R3集成之笔记(二)

在nutch与起点R3集成之笔记(一)中介绍了在起点R3中添加nutch要用到的索引字段,上述字段建好 ...

nutch与起点R3集成之笔记(三)

四、抓取网页,建立solr索引 在抓取网页前,要保证起点R3处在运行状态。即 在浏览器中键入 http ...

R简单数据分析

眼下大数据口号满天飞,今天拿我微信圈朋友一段时间内分享内容作为数据,用R包的算法实现简单分析。 由于微 ...

在Hadoop集群上运行R程序--安装RHadoop

Hadoop是由Revolution Analytics发起的一个开源项目,它可以将统计语言R与Had ...

Hadoop中使用 Gzip 压缩格式支持笔记

Hadoop中支持的压缩方式有多种,比如Gzip,bzip2,zlib等,其中Gzip是hadoop中 ...

请问起点R3能否做到完全支持MultiCore?

在RivuSchema类中实现了从数据库获取数据类型和索引结构表中的数据构建Schema.xml,但这 ...

Hadoop中使用lzo压缩格式支持笔记

通常Hadoop中的mapreduce作业都会产生大量都中间文件 ,当要处理当原始数据 非常大,并且在 ...

最新问答

更多

Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)

你得到IndexError的原因是你的输入文件显然不是完全用制表符分隔的。 这就是为什么当您尝试访问它时, splits[1]没有任何内容。 您的代码可以使用一些重构。 首先,你正在重复使用if -checks,这是不必要的。 这只是将cds0到7个字符,这可能不是你想要的。 我将以下内容放在一起,以演示如何重构您的代码,使其变得更加pythonic和干燥。 我无法保证它能够与您的数据集一起使用,但我希望它可以帮助您了解如何以不同的方式执行操作。 to_sort = [] # W

故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)

我不认为你可以链接一个特定的细节披露按钮瓦特/赛格。 我的故事板是非常程序化的B / C我使用了很多定制CGRect等。 所以我倾向于使用这样的东西: -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"ViewControllerIdentifer"

我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)

TestComplete不支持Gherkin功能文件。 但是,TestComplete具有SDK,因此可以自己为此创建扩展。 TestComplete does not support Gherkin feature files. However, TestComplete has SDK so it is possible to create an extension for this by yourself.

TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)

我没有做过这样的事情,但看看我认为可以看出错误的例子。 试试这个代码: static class Program { static void Main() { var tcpclient = new TcpClient("remote.example.com", 443); var tcpstream = tcpclient.GetStream(); var sslstream = new SslStream(tcpstream,

返回嵌套元素的索引(Return index of nested element)

您需要获取父li元素的索引。 否则,您将获得列表项内锚点的索引,该索引始终为零。 $(this.parentNode).index(); You need to get the index of the parent li element. Otherwise you are getting the index of the anchor inside the list item, which will always be zero. $(this.parentNode).index();

在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)

您需要多次迭代列表,我认为没有办法解决这个问题。 毕竟,在开始更改元素(第二遍)之前,首先必须确定不同元素的数量(第一遍)。 但是请注意,由于对index的重复调用而not in列表中具有O(n),因此可能具有最多O(n ^ 2)的不同元素的数量。 或者,您可以使用dict而不是value_map的list 。 字典比列表具有更快的查找速度,因此,复杂性应该确实在O(n)的数量级上。 您可以使用(1)字典理解来确定旧值到新值的映射,以及(2)用于创建更新子项的列表理解。 value_map =

Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)

选项1 你可以改变这一行: app.use( express.static(__dirname + '/puplic')); //my public folder. 至 app.use('/oneTime', express.static(__dirname + '/puplic')); //my public folder 选项2 我假设你在公共文件夹中有一个js文件夹,然后你需要更改你的HTML代码:

使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)

对于计时器值,请在服务器端本身每秒更新本地计时器。 每当有任何用户进来时,给他这个值以及计时器的总值。 然后客户端将根据dandavis评论在本地启动自己的计时器,但在服务器端保留一些间隔,如15或10秒,服务器将广播当前计时器值,以便客户端相应地进行同步。 简而言之,服务器将每隔10(n:你决定)秒后广播,但它将在本地每秒更新定时器变量。 每当客户端进入时,它将获得总计时器值和当前计时器值。 广播当前出价的休息功能可以以正常方式完成。 For timer value, keep updatin

如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)

IXmlSerializable也许? 注意我还添加了(对A ): [XmlElement("A", Namespace = "http://www.example.com/namespace")] public TestSoapHeaderTypeValuePair A {...} 代码如下: public class TestSoapHeaderTypeValuePair : IXmlSerializable { private string _type; private