简体   繁体   English

Rmarkdown和Shiny输入

[英]Rmarkdown and Shiny input

I'm attempting my first Markdown doc and everything has been going smoothly until I get the error 我正在尝试我的第一个Markdown文档,并且一切顺利,直到出现错误为止

  "Error in eval(expr, envir, enclos) : object 'input' not found" 

with this chunk 这个块

{r, echo=FALSE}

inputPanel(
radioButtons("category",label= "Select  Category",choices=c("diffPts","diffGF","diffGA","diffGD","diffpos"),inline = TRUE)
)
   renderPlot({
   ggplot(clubSeason, aes(x=team, y=input$category)) + geom_boxplot()
})

if I hardcode eg y="diffPts" the chart displays. 如果我对y="diffPts"进行硬编码, y="diffPts"显示图表。 Putting a print() around the ggplot does not help 在ggplot周围放一个print()并没有帮助

TIA TIA

Following runs fine for me. 以下对我来说很好。 The value of ìnput$category` is printied as expected 按预期方式打印ìnput$ category`的值

---
title: "Untitled"
runtime: shiny
output: html_document
---

```{r, echo=FALSE}
library(ggplot2)
inputPanel(
   radioButtons("category",label= "Select  Category",choices=c("diffPts","diffGF","diffGA","diffGD","diffpos"),inline = TRUE)
)
renderPlot({
   print(input$category)
   ggplot(faithful, aes(x=eruptions, y=waiting)) + geom_boxplot()
})
```

UPDATE: 更新:

The issue appears to be with the aes function being passed a string. 问题似乎是通过字符串传递了aes函数。 You can use aes_string instead: 您可以改用aes_string

renderPlot({
   ggplot(clubSeason, aes_string(x='team', y=input$category)) + geom_boxplot()
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM