我正在尝试创建一个有光泽的文档(R Markdown)。
我想使用ggplot2绘制基本的散点图,并可以选择与要绘制的要素相关的变量(即,在这种情况下,我将绘制一段时间内的辐射度,并且用户将能够选择要绘制的村庄)辐射指)。
inputPanel(
selectInput("v", label = "Village:",
choices = villages$village, selected = "Voas")
)
renderPlot({
ggplot(input$v, aes(x=date, y=radiance)) +
geom_point() +
geom_smooth(method=lm, formula = y ~ x)
})
当我“运行文档”时,出现此错误:
yaml :: yaml.load(...,eval.expr = TRUE)中的错误: 扫描仪错误:在这种情况下,第5行>第6列不允许映射值 调用:... parse_yaml_front_matter-> yaml_load->
我的YAML标头看起来像这样(我没有更改任何内容):
---
title: "Problem-Shiny"
runtime: shiny
output: html_document
---
谢谢。
答案 0 :(得分:1)
我不清楚您为什么最终遇到涉及D:\>create-react-app ananya
Creating a new React app in D:\ananya.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
npm ERR! Unexpected end of JSON input while parsing near '...e"},"devDependencies"'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\sethi\AppData\Roaming\npm-cache\_logs\2019-08-24T05_53_19_688Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... package.json
Deleting ananya/ from D:\
Done.
D:\>
的错误,但是我认为主要问题似乎在于您未正确使用yaml::yaml.load
。 ggplot
的第一个(data
)自变量是用于绘制的ggplot
。而是在代码中提供标量(data.frame
)。
由于您没有提供可重复的样本数据,因此以下是基于input$v
数据集的最小可重复示例。
首先使用具有mtcars
后端的RMarkdown文档
shiny
这将产生以下---
title: "Problem-Shiny"
runtime: shiny
output: html_document
---
```{r, echo=FALSE}
library(ggplot2)
inputPanel(
selectInput("carb", label = "Carburetors:",
choices = sort(mtcars$carb))
)
renderPlot({
ggplot(mtcars[mtcars$carb == input$carb, ], aes(mpg, disp)) +
geom_point() +
geom_smooth(method=lm, formula = y ~ x)
})
```
支持的HTML文档
作为替代方案,您可能希望使用shiny
数据结构,该数据结构返回经过过滤的(基于reactive
的输入)selectInput
。这样做的好处是,您还可以在其他地方使用经过过滤的data.frame
(不仅用于绘图)。
data()