这个问题与this类似,但又不完全相同。
基本上,我有许多表想使用DT::datatable(). 不幸的是,我不知道如何做。
以下代码有效,但我需要手动输入所有代码:
---
title: "Untitled"
format: html
---
```{r}
library(DT)
```
::: {.panel-tabset}
### table no. 1
```{r}
#| results: asis
datatable(mtcars)
```
### table no. 2
```{r}
#| results: asis
datatable(mtcars)
```
:::
Run Code Online (Sandbox Code Playgroud)
下面的方法有效,但不是datatable()使用一个简单的降价表,pander它不能给出所需的效果。
---
title: "Untitled"
format: html
---
```{r}
library(pander)
```
::: {.panel-tabset}
```{r}
#| results: asis
for(i in 1:2) {
cat(sprintf("\n### table no. %d\n\n", i))
cat(pander(mtcars))
}
```
:::
Run Code Online (Sandbox Code Playgroud)
以下代码不起作用,我不知道如何使其起作用:
---
title: "Untitled"
format: html
---
```{r} …Run Code Online (Sandbox Code Playgroud) 我有 R markdown 文档,我想动态创建其中包含 ggplotly 图形的选项卡
---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(ggplot2)
library(plotly)
```
```{r}
fig=ggplot(cars)+geom_point(aes(speed, dist))
```
# level 1
## level 2{.tabset .tabset-pills}
```{r echo=FALSE, results='asis'}
for (h in 1:3){
cat("###", h,'{-}', '\n\n')
ggplotly(fig)
cat( '\n\n')
}
```
Run Code Online (Sandbox Code Playgroud)
我知道它与普通ggplot图表不同,我在这里查看了解决方案:在此处输入链接描述,但它对我不起作用
我正在使用plotly转换ggplot2图表并将它们放在knitr html输出中.这是报告的工作副本. http://rpubs.com/kausti/NSEFO-23-Mar-2016 第一张图是情节图,而以下图则不是.我希望他们是情节图表,但我被卡住了.
在下面的代码中,plotChart函数返回一个ggplot2图.这段代码有效!
for (tick in tradeOps$ticker)
{
tmpDF = filter(tradeOps, ticker == tick)
p = plotChart(tick = tick,Entry = tmpDF$Entry, Target = tmpDF$Target, SL= tmpDF$SL, TradeType = tmpDF$TradeType, data = wd)
p = p + annotate("text", x = as.Date(tmpDF$Date)+30, y = tmpDF$Entry, label = tmpDF$Entry, colour = "blue")
p = p + annotate("text", x = as.Date(tmpDF$Date)+30, y = tmpDF$Target, label = tmpDF$Target)
p = p + annotate("text", x = as.Date(tmpDF$Date)+30, y = tmpDF$SL, label = tmpDF$SL)
print(p) …Run Code Online (Sandbox Code Playgroud)