.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 usekable()
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:
When I
Knit
the file to PDF I can see the output.
Here is a screenshot:
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") ```
满意答案
您必须为每个输出设置不同的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 specifyresults = '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)
.Rmd中使用的R - kable()不会在笔记本中显示输出(R - kable() used in .Rmd does not show output in notebook)
使用xtable或knitr :: kable抑制.Rmd文件中的自动表名和编号(Suppress automatic table name and number in an .Rmd file using xtable or knitr::kable)
为什么R引用旧的.Rmd文件(why is R referring to old .Rmd file)
访问.rmd文件的名称并在R中使用(Access name of .rmd file and use in R)
结合Shiny app和Rmd文件(Combining Shiny app and Rmd file)
来自另一个Rmd中的Rmd文件的源代码(Source code from Rmd file within another Rmd)
Knitr和kable没有找到数据框(Knitr and kable not finding data frame)
如何在从.rmd编织到Word时使用格式化Kable表(带书)(How to format kable table when knit from .rmd to Word (with bookdown))
knit pdf中的kable()看起来过大了(kable() in knit pdf appears oversized)
相关文章
更多nutch与起点R3集成之笔记(四)
nutch与起点R3集成之笔记(一)
javax.imageio.IIOException: Can't create output stream!的解决方案
nutch与起点R3集成之笔记(二)
nutch与起点R3集成之笔记(三)
R简单数据分析
在Hadoop集群上运行R程序--安装RHadoop
Hadoop中使用 Gzip 压缩格式支持笔记
请问起点R3能否做到完全支持MultiCore?
Hadoop中使用lzo压缩格式支持笔记
最新问答
更多Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)
故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)
我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)
TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)
返回嵌套元素的索引(Return index of nested element)
在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)
Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)
Javascript错误:未捕获TypeError:无法读取null的属性'value'[duplicate](Javascript error: Uncaught TypeError: Cannot read property 'value' of null [duplicate])
使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)
如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)
Copyright ©2023 656463.com All Rights Reserved.滇ICP备2022006988号-50
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们,本站将尽快处理。谢谢合作!