kable in Rmarkdown file

kable
#1

Hello,

so I created an R markdown file as in File -> New File -> R Markdown.
It created a prebuild R markdown document and when I knit it to HTML with the below code.

Summary of (cars) and plot of pressure pops out. Looks good, works fine.

summary(cars)
plot(pressure)

but when I added the below code. No charts or graph pops up, instead the written text are in the R markdown file. I got the below code from this link. https://haozhu233.github.io/kableExtra/awesome_table_in_html.html

kable(dt) %>%
kable_styling("striped", full_width = F) %>%
column_spec(5:7, bold = T) %>%
row_spec(3:5, bold = T, color = "white", background = "#D7261E")

Please advise why that is and how I can get it to show the charts of the last code ?

0 Likes

#2

Are you putting the code inside a code chunk? do you have all the needed libraries installed? do you have loaded the libraries? Your code should look like this.

---
title: "test"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(knitr)
library(kableExtra)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r}
dt <- mtcars[1:5, 1:6]
kable(dt) %>%
kable_styling("striped", full_width = F) %>%
column_spec(5:7, bold = T) %>%
row_spec(3:5, bold = T, color = "white", background = "#D7261E")
```

image

0 Likes

#3

Thank you, let me give it a try.
No my code wasn't in the code Chunk, now I understand. Thx to you.

0 Likes

#4

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

0 Likes

closed #5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

0 Likes