簡體   English   中英

knitr + pandoc:查看html幻燈片時看不到情節

[英]knitr + pandoc: cannot see plot when viewing html slides

我已經使用knitr包和pandoc在R Studio中成功創建了2個測試幻燈片。 在R studio中使用“knitr”按鈕時的R markdown文件看起來很好並且正確顯示了圖表,但是當使用pandoc從.Rmd文件生成.html文件時,在瀏覽器中運行似乎丟失了所有代碼包裝和圖表Rmd文件。 這是我的兩個腳本:

mdown.Rmd:

Title
========================================================

This is an R Markdown document. Markdown is a simple formatting syntax for authoring web pages (click the **MD** toolbar button for help on Markdown).

When you click the **Knit HTML** button a web page 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}
summary(cars)
```

---

You can also embed plots, for example:

```{r fig.width=7, fig.height=6}
plot(cars)
```

以及運行它的腳本:

# Load packages
setwd("~Documents")
require(knitr)
require(markdown)

# Create slides
knit('mdown.Rmd')
system('pandoc -s -t slidy mdown.Rmd -o mdown.html')

這里也是pandoc生成的html文件

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="generator" content="pandoc" />
  <link rel="stylesheet" type="text/css" media="screen, projection, print" 
    href="http://www.w3.org/Talks/Tools/Slidy/slidy.css" /> 
  <script src="http://www.w3.org/Talks/Tools/Slidy/slidy.js.gz"
    charset="utf-8" type="text/javascript"></script>
</head>
<body>
<div class="slide">

<h1>Title</h1>
<p>This is an R Markdown document. Markdown is a simple formatting syntax for authoring web pages (click the <strong>MD</strong> toolbar button for help on Markdown).</p>
<p>When you click the <strong>Knit HTML</strong> button a web page 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:</p>
<p><code>{r} summary(cars)</code></p>
</div>

<div class="slide">

<p>You can also embed plots, for example:</p>
<p><code>{r fig.width=7, fig.height=6} plot(cars)</code></p>
</div>
</body>
</html>

我在哪里錯了?

您正在使用pandoc處理.Rmd文件,您應該處理通過knitr運行mdown.Rmd后創建的.md文件。

knit('mdown.Rmd')
system('pandoc -s -t slidy mdown.md -o mdown.html')

.Rmd文件只是您在上面顯示的原始文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM